kafka-console-consumer.sh: read data from Kafka topics and write it to standard output
kafka-console-consumer.sh [options]
Options you will use
--bootstrap-server <String: server to connect to>- REQUIRED: the Kafka broker(s) to connect to, host:port[,host:port]. Give more than one: the first may be the broker that is down.
--topic <String: topic>- the topic to consume.
--include <String: regex>- consume every topic matching the regex.
--group <String: group>- the consumer group: joins it and commits offsets (never a production group).
--from-beginning- start at the oldest record if the group has no committed offset (default: the end).
--partition <Integer>- read one partition (not with --group).
--offset <String>- with --partition: earliest, latest or an offset number.
--max-messages <Integer>- exit after this many records.
--timeout-ms <Integer>- exit if no record arrives for this long (an ERROR line + TimeoutException, not a failure of the cluster).
--formatter-property <String: prop>- print.timestamp, print.partition, print.offset, print.key, print.headers, key.separator (--property is deprecated).
--isolation-level <String>- read_committed to skip records of aborted transactions.
Examples
$ kafka-console-consumer.sh --bootstrap-server kafka-1:9092 --topic orders --from-beginning --max-messages 3the three oldest records
$ kafka-console-consumer.sh --bootstrap-server kafka-1:9092 --topic orders --partition 0 --offset earliest --formatter-property print.offset=true --timeout-ms 5000one partition with offsets
Gotchas
- A new consumer starts at the END: on a quiet topic it prints nothing. --from-beginning or --partition N --offset earliest.
- The first stderr line advertises the KIP-848 consumer protocol when the classic one is used.
Taught in
Try kafka-console-consumer.sh in a real terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.