Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignoring element in stream #172

Open
hamid512 opened this issue Sep 11, 2020 · 1 comment
Open

Ignoring element in stream #172

hamid512 opened this issue Sep 11, 2020 · 1 comment

Comments

@hamid512
Copy link

how i prevent sending empty string '' if number is odd, like prevent .to from running and just move to next stream data? if defeats the purpose of multiple branching topics for me
my code

`const checkforOdd = (kafkaMessage) => {
const value = kafkaMessage.value.toString("utf8");
// console.log(value)
if(!(parseInt(value) % 2 == 0)){
return value
}else{
return ''
}

};
const checkforEven = (kafkaMessage) => {
const value = kafkaMessage.value.toString("utf8");
if(parseInt(value) % 2 == 0){

    return value
 }
 else{
      return ''
 }

};

const kafkaStreams = new KafkaStreams(config);

kafkaStreams.on("error", (error) => {
console.log("Error occured:", error.message);
});

const stream = kafkaStreams.getKStream('test-topic');
const [one$, two$] = stream
.branch([() => true, () => true]);

const producerPromiseOne = one$
.map(checkforOdd)
.to("odd");

const producerPromiseTwo = two$
.map(checkforEven)
.to("even");`

@hamid512
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant