liveBook · Manning

Print

As explained in Kafka Streams in Action, Second Edition

KStream.print is a Kafka Streams terminal operation that prints stream records to an output destination such as the console.

KStream.print() displays records flowing through a Kafka Streams topology, typically at the console. It is especially useful during development because feedback comes directly from the application rather than an external console consumer. section 6.5

print is a terminal operation: it returns void, ends the KStream chain, and cannot be followed by another stream transformation. Use it after a transformation when you want to inspect results; use peek when printing must occur between operators. section 6.5 section 6.7

Inspecting transformed records

KStream<String, String> upperCasedStream = simpleFirstStream.mapValues(value -> value.toUpperCase()); upperCasedStream.print(Printed.toSysOut()); upperCasedStream.to("out-topic", Produced.with(stringSerde, stringSerde)); The stream is printed after uppercasing, then separately written to Kafka. Printing does not replace the output-topic operation; it provides visual feedback while the topology runs. section 6.5

Printing KStream and KTable results

A KStream prints each stock-ticker record, while a KTable must first be converted with toStream(). With duplicate keys, the KStream shows all nine records in the example, whereas the KTable shows three update results. section 8.1.2

How Kafka Streams in Action, Second Edition covers it

How deep it goes
Explains console output, terminal behavior, chaining limits, and the contrast with peek, but does not detail implementation internals.
Examples
Uses uppercase word transformation, ZMart purchase processing, and stock-ticker KStream-versus-KTable output examples.
What it assumes
Assumes familiarity with KStream records and transformations while demonstrating console inspection from concrete Java examples.
What you can do after
Diagnose/debug with it by viewing records emitted at a topology point and comparing stream output with table updates.
How it connects
Connects KStream.print with KStream.peek, KStream.to, KStream.foreach, KTable.toStream, and Serdes.

Also explained in

Compare how 5 books explain print →

Related concepts

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