liveBook · Manning

Kafka-console-producer

As explained in Apache Kafka in Action

kafka-console-producer.sh is an Apache Kafka command-line utility that publishes records to a topic from console input.

kafka-console-producer.sh publishes records to a Kafka topic from console input. It is useful for testing a price-change flow: connect to a local broker, select products.prices.changelog, and send each update as a message. section 2.2

Pipe one record into a topic

echo "coffee pads 10" | kafka-console-producer.sh --topic products.prices.changelog --bootstrap-server localhost:9092 sends one line as a message. The producer prints no success confirmation when input is piped, so verify delivery with a consumer. section 2.2

Interactive mode sends one message for every line entered. The process continues until Ctrl-D sends EOF; a consumer running in another terminal can display new records promptly. section 2.4

Practical operating points:

  • Use --topic to choose the destination and --bootstrap-server localhost:9092 to connect to the local Kafka cluster. section 2.2
  • Run multiple producer instances to represent departments writing different product updates in parallel. section 2.4
  • Pair the producer with independent consumers to observe live records or replay retained history with --from-beginning. section 2.4
  • Expect connectivity errors when Kafka is unavailable; Confluent distributions omit .sh, and Windows users can use .bat scripts or WSL. section 2.0 section 2.2
$ echo "coffee pads 10" | kafka-console-producer.sh \
    --topic products.prices.changelog \
    --bootstrap-server localhost:9092

Shows the smallest complete command for publishing a piped record to a topic. section 2.2

# Don't forget: use Ctrl-D to stop the producer
$ kafka-console-producer.sh \
    --topic products.prices.changelog \
    --bootstrap-server localhost:9092

Shows the interactive invocation used to type successive records and stop with Ctrl-D. section 2.4

How Apache Kafka in Action covers it

How deep it goes
Explains topic and broker options, line-based delivery, stopping behavior, parallel producers, and consumer verification.
Examples
Uses coffee, pillow, and blanket price records with piped, interactive, parallel-producer, and consumer-replay demonstrations.
What it assumes
Assumes an installed and running Kafka cluster plus an available destination topic.
What you can do after
Operate/configure the command to publish individual records and observe them through Kafka consumers.
How it connects
Connects Kafka topics, brokers, consumers, message retention, historical replay, and parallel producers.

Also explained in

Compare how 2 books explain kafka-console-producer →

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.