nodefluent / kafka-streams

equivalent to kafka-streams :octopus: for nodejs :sparkles::turtle::rocket::sparkles:
https://nodefluent.github.io/kafka-streams/
MIT License
830 stars 111 forks source link

Ignoring element in stream #172

Open hamid512 opened 4 years ago

hamid512 commented 4 years ago

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 commented 4 years ago

@rsilvestre @elmarx @crcastle @drublic