Skip to content
Latchkey

kafka-console-producer.sh: Send Test Messages

kafka-console-producer.sh --topic <name> --bootstrap-server <host:port> reads lines from stdin and publishes each as a message to the topic.

For a quick smoke test that a topic accepts writes, the console producer is the fastest path. It is also handy for seeding fixture data before a consumer test.

What it does

kafka-console-producer.sh reads newline-delimited input and produces one record per line to the named topic. With --property it can parse a key and value from each line, letting you control partitioning by key.

Common usage

Terminal
# pipe two messages non-interactively
printf 'msg1\nmsg2\n' | kafka-console-producer.sh \
  --topic orders --bootstrap-server localhost:9092
# keyed messages: key:value separated by a colon
printf 'k1:v1\nk2:v2\n' | kafka-console-producer.sh \
  --topic orders --bootstrap-server localhost:9092 \
  --property parse.key=true --property key.separator=:

Options

FlagWhat it does
--topic <name>Destination topic
--bootstrap-server <host:port>Broker to connect to
--property parse.key=trueParse a key from each input line
--property key.separator=<c>Character that splits key from value
--producer-property acks=allSet a producer config such as acks
--producer.config <file>Load producer properties from a file

In CI

Feed input via a pipe or heredoc so the command exits instead of blocking on the interactive prompt. Create the topic first: producing into a missing topic either fails or silently auto-creates a single-partition topic depending on broker config.

Common errors in CI

"UNKNOWN_TOPIC_OR_PARTITION" (WARN) means the topic does not exist yet; create it before producing. "Connection to node -1 ... could not be established" means the broker is unreachable. "TimeoutException: Topic orders not present in metadata after 60000 ms" means metadata never resolved, usually the same missing-topic or broker-not-ready cause.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →