KStream.split begins branching a KStream and returns a BranchedKStream. Predicates route records into separate processing paths while preserving the original key and value types. section 6.6 section 6.6.2
Build a branching topology in four steps:
- Call split() on the source KStream. section 6.6.2
- Add each branch with branch(), a Predicate, and a Branched processor. section 6.6.2
- Finish with defaultBranch() to retain nonmatching records or noDefaultBranch() to drop them. section 6.6.2
- Collect returned KStream objects through the resulting map when branches need further topology work. section 6.6.2
Routing ZMart purchases
Predicate<String, Purchase> isCoffee = (key, purchase) -> purchase.getDepartment().equalsIgnoreCase("coffee"); Predicate<String, Purchase> isElectronics = (key, purchase) -> purchase.getDepartment().equalsIgnoreCase("electronics"); purchaseKStream.split() .branch(isCoffee, Branched.withConsumer(s -> s.to("coffee-topic"))) .branch(isElectronics, Branched.withConsumer(s -> s.to("electronics"))) .defaultBranch(Branched.withConsumer(s -> s.to("purchases"))); section 6.6
Figure 6.8 Creating branches for the two specific purchase types
Visualizes a single purchase stream dividing into branches for specific purchase types and a default path. section 6.6.2
