Skip to content

Instantly share code, notes, and snippets.

@nfo
Last active April 26, 2017 10:20
Show Gist options
  • Save nfo/c4936a24601352db23b18653a8ccc352 to your computer and use it in GitHub Desktop.
Save nfo/c4936a24601352db23b18653a8ccc352 to your computer and use it in GitHub Desktop.
Kafka Streams: Calling series `KStream.branch()` to route records to n topics
KStream<Key, Value>[] branches = stream.branch((k, v) -> v.getType().equals("abc"));
branches[0].to(keySerde, valueSerde, "topic-abc");
branches = branches[1].branch((k, v) -> v.getType().equals("def"));
branches[0].to(keySerde, valueSerde, "topic-def");
branches = branches[1].branch((k, v) -> v.getType().equals("ghi"));
branches[0].to(keySerde, valueSerde, "topic-ghi");
// ....
@PGryllos
Copy link

Which version of kafka streams are you referring to? This is not supposed to work on 0.10.0 and later as the branch with one predicate will result in one stream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment