liveBook · Manning

Split

As explained in Apache Kafka in Action

split is a stream-processing function that routes records into multiple branches according to predicates or conditions.

split() routes each record into one of several branches when different conditions require different processing. It offers an alternative to multiple filter() calls, especially when conditions represent mutually exclusive categories. section 12.2.1

Routing products by price

A prices stream can send products below 10 to prices-cheap, products below 100 to prices-midrange, and all remaining products to prices-expensive. Branches can continue processing through Branched.withConsumer(), such as writing each branch to its own topic. Branches are evaluated from top to bottom; the first true predicate handles the record, while defaultBranch() catches records that match no earlier predicate. section 12.2.1

prices.split()    #1
    .branch((key, value) -> value.price < 10,    #2
        Branched.withConsumer(    #3
            (stream) -> stream.to("prices-cheap")))    #4

    .branch((key, value) -> value.price < 100,    #5
        Branched.withConsumer(
            (stream) -> stream.to("prices-midrange")))

    .defaultBranch(Branched.withConsumer(    #6
            (stream) -> stream.to("prices-expensive")))

Inspect the complete Kafka Streams topology for price-based branching, including predicates, branch consumers, output topics, and the default branch. section 12.2.1

How Apache Kafka in Action covers it

How deep it goes
Explains predicates, top-to-bottom evaluation, default handling, and downstream consumers, but does not descend into stateful processing internals.
Examples
Demonstrates price-based branches that write cheap, midrange, and expensive products to separate Kafka topics.
What you can do after
Apply it via Kafka Streams to build mutually exclusive, condition-based branches with explicit fallback handling.
How it connects
Connects split() with filter(), merge(), branching, Kafka Streams, and processor topologies.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Apache Kafka in Action. The section links point to the parts of the book it draws on.