首页  

kafka命令行发送接收消息     所属分类 kafka 浏览量 1123
先启动消费端


发送消息
bin/kafka-console-producer.sh --broker-list localhost:2 --topic kafka_demo_test_topic   
>a
>b
>c


消费消息
dugang$ bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic kafka_demo_test_topic 
a
b
c


消费端可加参数   --from-beginning  
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic kafka_demo_test_topic  --from-beginning

--topic
--group
--partition  partitionid
--offset
--group  consumerGroupId


The partition is required when offset is specified.
partition 和  offset 一起使用

bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic kafka_demo_test_topic  --group group001 --partition 0  --offset 7 


查看消费情况
./bin/kafka-consumer-groups.sh --bootstrap-server 127.0.0.1:9092 --describe --group group001


不指定 partition 和 offset
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic kafka_demo_test_topic  --group group001 

./bin/kafka-consumer-groups.sh --bootstrap-server 127.0.0.1:9092 --describe --group group001

TOPIC                 PARTITION  CURRENT-OFFSET  LOG-END-OFFSET  LAG             CONSUMER-ID                                     HOST            CLIENT-ID
kafka_demo_test_topic 1          19              19              0               consumer-1-8fc02d72-a135-42c3-a429-46a259bc2eb1 /127.0.0.1      consumer-1
kafka_demo_test_topic 2          20              20              0               consumer-1-8fc02d72-a135-42c3-a429-46a259bc2eb1 /127.0.0.1      consumer-1
kafka_demo_test_topic 5          17              17              0               consumer-1-8fc02d72-a135-42c3-a429-46a259bc2eb1 /127.0.0.1      consumer-1
kafka_demo_test_topic 0          15              15              0               consumer-1-8fc02d72-a135-42c3-a429-46a259bc2eb1 /127.0.0.1      consumer-1
kafka_demo_test_topic 4          15              15              0               consumer-1-8fc02d72-a135-42c3-a429-46a259bc2eb1 /127.0.0.1      consumer-1
kafka_demo_test_topic 3          14              14              0               consumer-1-8fc02d72-a135-42c3-a429-46a259bc2eb1 /127.0.0.1      consumer-1

上一篇     下一篇
kafka在zookeeper中的元数据

Kafka配置参数

kafka集群搭建

zookeeper命令行zkCli使用

spring构造注入优缺点

springboot 构造注入实例