LinuxCommandLibrary

kafkacat

command-line Kafka producer and consumer

TLDR

Produce messages

$ echo "[message]" | kafkacat -P -b [localhost:9092] -t [topic]
copy
Consume messages
$ kafkacat -C -b [localhost:9092] -t [topic]
copy
Consume from beginning
$ kafkacat -C -b [localhost:9092] -t [topic] -o beginning
copy
List topics
$ kafkacat -L -b [localhost:9092]
copy
Produce from file
$ kafkacat -P -b [localhost:9092] -t [topic] [file.txt]
copy
Consume with format
$ kafkacat -C -b [localhost:9092] -t [topic] -f '[%T] %k: %s\n'
copy

SYNOPSIS

kafkacat [options]

DESCRIPTION

kafkacat (also known as kcat) is a command-line Kafka producer and consumer. It's faster and simpler than Kafka's built-in shell scripts, useful for testing and debugging.

PARAMETERS

-P

Producer mode.
-C
Consumer mode.
-L
Metadata list mode.
-b brokers
Broker list.
-t topic
Topic name.
-p partition
Partition number.
-o offset
Offset: beginning, end, stored, or number.
-K delim
Key delimiter.
-f format
Output format string.
-c count
Exit after consuming count messages.
-e
Exit at end of topic.
-X property=value
Set librdkafka property.

FORMAT STRINGS

$ %T  - Timestamp
%k  - Key
%s  - Message (payload)
%p  - Partition
%o  - Offset
%t  - Topic
copy

CAVEATS

Renamed to kcat in newer versions. Requires librdkafka. Not included with Kafka distribution. Some features need specific librdkafka version.

HISTORY

kafkacat was created by Magnus Edenhill, who also created librdkafka. It's been renamed to kcat but kafkacat remains widely used.

SEE ALSO

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community