kafka命令行生产者消费者测试
程序员文章站
2022-07-12 17:41:37
...
【README】
基于命令行开启生产者,消费者线程,测试kafka的消费转发功能;
【1】生产者与消费者
生产者201
[[email protected] logs]# kafka-console-producer.sh --topic first --broker-list centos201:9092
>hello-world
>sichuan-changdu
>
消费者202
[[email protected] logs]# kafka-console-consumer.sh --topic first --zookeeper centos201:2181
Using the ConsoleConsumer with old consumer is deprecated and will be removed in a future major release. Consider using the new consumer by passing [bootstrap-server] instead of [zookeeper].
hello-world
sichuan-changdu
注意: 消费者202在生产者201 发送消息前就已经启动了; 所以能够收到所有生产者数据;
此后203再启动消费者线程,如下:
[[email protected] logs]# kafka-console-consumer.sh --topic first --zookeeper centos201:2181
Using the ConsoleConsumer with old consumer is deprecated and will be removed in a future major release. Consider using the new consumer by passing [bootstrap-server] instead of [zookeeper].
执行结果说明:显然201机器开启生产者线程,写入了数据到 kafka, hello-world等; 202机器开启了消费者线程,可以收到201机器写入的数据; 但201写完之后, 203 再开启了消费者线程,203收不到之前201写入的数据;
但当我们在开启消费者线程时,加上参数 --from-beginning 时可以消费或收到201之前写的数据;只不过消息无序了;
[[email protected] logs]# kafka-console-consumer.sh --topic first --zookeeper centos201:2181 --from-beginning
Using the ConsoleConsumer with old consumer is deprecated and will be removed in a future major release. Consider using the new consumer by passing [bootstrap-server] instead of [zookeeper].
sichuan-changdu
hello-world
sichuan-deyang
补充:因为 提示命令过期,所以使用 bootstrap-server 来启动消费者
[email protected] logs]# kafka-console-consumer.sh --topic first --bootstrap-server centos201:9092
sichuan-nanchong
-- 从头开始消费
[[email protected] logs]# kafka-console-consumer.sh --topic first --bootstrap-server centos201:9092 --from-beginning
sichuan-deyang
sichuan-nanchong
sichuan-changdu
hello-world
sichuan-mianyang
推荐阅读
-
Python 使用python-kafka类库开发kafka生产者&消费者&客户端
-
kafka的生产者和消费者代码示例
-
springboot配置kafka生产者和消费者详解
-
kafka命令行生产者消费者测试
-
Kafka 生产者消费者模式 写入/读取数据 [ 命令行/Java 代码 ]
-
kafka_2.11-0.10.2.1 的生产者 消费者的示例(new producer api)
-
Python 使用python-kafka类库开发kafka生产者&消费者&客户端
-
Java实现Kafka的生产者和消费者例子
-
kafka的生产者和消费者代码示例
-
springboot配置kafka生产者和消费者详解