liveBook · Manning

Filtering

As explained in Apache Kafka in Action

filter is a stream-processing function that retains only records for which a predicate returns true.

Filtering selects records from a continuous stream by applying a predicate to each message. Only records for which the predicate returns true continue through the stream. section 12.2.1

Keep significant price changes

For a stream of product price changes, retain only messages whose new price exceeds $100: filter((key, value) -> value.price > 100). Lower-priced changes are discarded, while qualifying records preserve their existing key and value. section 12.2.1

filter((key, value) -> value.price > 100)

Use the concise Kafka Streams predicate to inspect the value of every record and retain qualifying price changes. section 12.2.1

Apply filtering with these boundaries in mind:

  • Use map() or mapValues() when records must be changed; filter() only selects records. section 12.2.1
  • Chain filters to create categories such as cheap, midrange, and expensive prices, or use split() to branch a stream into destinations. section 12.2.1
  • Prefer mapValues() when changing only values, because changing keys can require repartitioning and reduce performance. section 12.2.1

How Apache Kafka in Action covers it

How deep it goes
Defines predicate-based selection and demonstrates price filtering, but stops short of implementation internals.
Examples
Uses product price changes, a greater-than-$100 predicate, price-range branches, and Kafka topic outputs.
What it assumes
Assumes basic stream and message concepts while introducing predicates through a concrete price-change example.
What you can do after
Apply it via Kafka Streams to retain records matching a predicate and route selected data through a topology.
How it connects
Connects filtering with Kafka Streams, predicates, map, mapValues, split, merge, and aggregation.

Also explained in

Compare how 33 books explain filtering →

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.