← 返回命令列表

Linux command

kcat 命令

趣味

复制后可按需替换文件名、目录或参数。

常用示例

Consume messages from topic

kcat -b [localhost:9092] -t [topic] -C

Produce message to topic

echo "[message]" | kcat -b [localhost:9092] -t [topic] -P

List metadata

kcat -b [localhost:9092] -L

Consume with custom format

kcat -b [localhost:9092] -t [topic] -C -f '%k: %s\n'

Consume from beginning

kcat -b [localhost:9092] -t [topic] -C -o beginning

Query watermarks

kcat -b [localhost:9092] -t [topic] -Q

说明

kcat (formerly kafkacat) is a generic non-JVM producer and consumer for Apache Kafka. Written in C using librdkafka, it provides a lightweight CLI for interacting with Kafka clusters. It supports producing, consuming, listing metadata, querying offsets, and working with Avro/JSON payloads via Schema Registry.

参数

-b _brokers_
Comma-separated Kafka broker list (host:port).
-t _topic_
Topic to produce to or consume from.
-p _partition_
Partition to produce to or consume from.
-C
Consumer mode.
-P
Producer mode.
-L
Metadata list mode.
-Q
Query offsets by timestamp.
-G _group_
High-level consumer group (requires broker >= 0.9.0).
-o _offset_
Starting offset (beginning, end, stored, or numeric; negative counts from end).
-e
Exit after consuming the last message.
-q
Quiet mode, no informational output.
-f _format_
Output format string (e.g. `%t %p %o %k %s\n`).
-J
Output messages in a JSON envelope.
-K _sep_
Key delimiter for produce/consume.
-D _sep_
Message delimiter (default newline).
-X _prop=val_
Set a librdkafka configuration property.
-F _file_
Read librdkafka config from file.

FAQ

What is the kcat command used for?

kcat (formerly kafkacat) is a generic non-JVM producer and consumer for Apache Kafka. Written in C using librdkafka, it provides a lightweight CLI for interacting with Kafka clusters. It supports producing, consuming, listing metadata, querying offsets, and working with Avro/JSON payloads via Schema Registry.

How do I run a basic kcat example?

Run `kcat -b [localhost:9092] -t [topic] -C` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -b _brokers_ do in kcat?

Comma-separated Kafka broker list (host:port).