BranchedKStream is the branching stage returned by KStream.split(). It creates predicate-gated branches and terminates them with defaultBranch() or noDefaultBranch(). section 6.6.2
A branching topology follows this sequence:
- Call split() on the original KStream. section 6.6.2
- Call branch() with a Predicate and Branched handler; matching records flow through that branch. section 6.6.2
- Finish with defaultBranch() for unmatched records or noDefaultBranch() to drop them. section 6.6.2
- Use the returned Map<String, KStream<K, V>> when Branched objects expose newly created streams; branch key and value types remain unchanged. section 6.6.2
Route purchases by department
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.2
Figure 6.8 Creating branches for the two specific purchase types
Visualizes how specific purchase types become separate branches while unmatched events continue through the default path. section 6.6.2
