杭州电子商务网站开发,手机版素材网站,合肥制作网站,中信云 做网站【README】
基于命令行开启生产者#xff0c;消费者线程#xff0c;测试kafka的消费转发功能#xff1b;
【1】生产者与消费者
生产者201
[rootcentos201 logs]# kafka-console-producer.sh --topic first --broker-list centos201:9092
hello-world
sichuan-c…【README】
基于命令行开启生产者消费者线程测试kafka的消费转发功能
【1】生产者与消费者
生产者201
[rootcentos201 logs]# kafka-console-producer.sh --topic first --broker-list centos201:9092
hello-world
sichuan-changdu消费者202
[rootcentos202 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再启动消费者线程如下
[rootcentos203 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之前写的数据只不过消息无序了 [rootcentos203 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 来启动消费者
rootcentos202 logs]# kafka-console-consumer.sh --topic first --bootstrap-server centos201:9092
sichuan-nanchong -- 从头开始消费
[rootcentos202 logs]# kafka-console-consumer.sh --topic first --bootstrap-server centos201:9092 --from-beginning
sichuan-deyang
sichuan-nanchong
sichuan-changdu
hello-world
sichuan-mianyang