Linux command
kafkacat 命令
趣味
涉及管道、覆盖或删除,执行前请先确认路径和参数。
常用示例
Produce messages
echo "[message]" | kafkacat -P -b [localhost:9092] -t [topic]
Consume messages
kafkacat -C -b [localhost:9092] -t [topic]
Consume from beginning
kafkacat -C -b [localhost:9092] -t [topic] -o beginning
List topics
kafkacat -L -b [localhost:9092]
Produce from file
kafkacat -P -b [localhost:9092] -t [topic] [file.txt]
Consume with format
kafkacat -C -b [localhost:9092] -t [topic] -f '[%T] %k: %s\n'
Produce with key
echo "[key]:[value]" | kafkacat -P -b [localhost:9092] -t [topic] -K ":"
Consume N messages
kafkacat -C -b [localhost:9092] -t [topic] -c [10]
说明
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.
参数
- -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.
- -G _group_ _topic_
- Consumer group mode (high-level balanced consumer).
- -X _property=value_
- Set librdkafka property (e.g., security.protocol=SSL).
FAQ
What is the kafkacat command used for?
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.
How do I run a basic kafkacat example?
Run `echo "[message]" | kafkacat -P -b [localhost:9092] -t [topic]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -P do in kafkacat?
Producer mode.