liveBook · Manning

Stream processor

As explained in Apache Kafka in Action

A stream processor is a component that examines, transforms, combines, produces, or routes records in a continuously processed data stream.

Suppose product prices arrive continuously and you need to select expensive items, convert their prices, or route them to different topics. A stream processor applies one operation to records as they flow through a pipeline. Kafka Streams and Apache Flink connect processors so that input can become filtered, transformed, or aggregated output. section 12.2

Choose a processor for the job:

  • Read: `builder.stream("products.prices.changelog")` creates a stream from a Kafka topic. section 12.2.1
  • Select: `filter()` keeps records whose predicate is true, such as prices above $100. section 12.2.1
  • Transform: `map()` can change both key and value; `mapValues()` changes only the value. section 12.2.1
  • Combine or route: `merge()` combines streams; `split()` sends records down branches selected by conditions. section 12.2.1
  • Count: `groupByKey().count()` counts records by key. Counting is stateful because it retains intermediate results. section 12.2.1 section 12.7
mapValues((key, value) -> value.price * 100)

This `mapValues()` example converts a price from dollars to cents without changing the record key. Prefer it over `map()` when the key should stay the same: changing keys can require repartitioning and reduce performance. 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")))

The price stream branches into cheap, midrange, and expensive outputs, each written to its own Kafka topic. It shows how connected processors turn one incoming stream into several useful outputs. section 12.2.1

Connect processors into a topology for longer workflows, such as merging streams before filtering or aggregating them. Unlike a simple filter or conversion, an aggregation must maintain state. Stream processing also requires accounting for eventual consistency; key-value stores and changelog topics help protect stored state against data loss. section 12.7

How Apache Kafka in Action covers it

How deep it goes
Works through source, filter, mapping, branching, and counting operations, while deferring streaming SQL details.
Examples
Uses product price changes for threshold filtering, dollar-to-cent conversion, price-band routing, and keyed counts.
What it assumes
Introduces topic reads, key–value records, and predicates through source, filter, and mapping examples.
What you can do after
Apply it via Kafka Streams to filter prices, transform values, route branches, and count records by key.
How it connects
Connects Kafka topics, functional programming, processor topologies, stateful aggregation, and streaming SQL.

Also explained in

Compare how 3 books explain stream processor →

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.