kafka入门系列3----kafka生产消费

版权声明: https://blog.csdn.net/xichengqc/article/details/90322245
  1. 创建一个叫topic131_01的主题
[root@localhost bin]# sh kafka-topics.sh --create --zookeeper 192.168.133.131:2181 --replication-factor 1 --partitions 1 --topic topic131_01
Created topic "topic131_01".

切换到kafka-logs目录下,可以看到有名字为topic131_01-0的目录

[root@localhost ~]# cd /home/software/kafka_2.11-1.0.0/kafka-logs

同时也可以通过命令查看当前的所有主题

[root@localhost bin]# sh kafka-topics.sh --list --zookeeper 192.168.133.131:2181
topic131_01
  1. 向该主题发送消息
sh kafka-console-producer.sh --broker-list 192.168.133.131:9092 --topic topic131_01
>hello kafka

进入kafka-logs目录下的,查看发送的消息

[root@localhost topic131_01-0]# tail -f 00000000000000000000.log 
CplHKj®
        j®
           ÿÿÿÿÿÿÿÿÿÿÿÿÿÿ"hello kafka
  1. 启动consumer
 [root@localhost bin]# sh kafka-console-consumer.sh --zookeeper 192.168.133.131:9092 --topic topic131_01 --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]
.hello kafka

新版本启动命令为:

[root@localhost bin]# sh kafka-console-consumer.sh --bootstrap-server 192.168.143.111:9092 --topic topic131_01 --from-beginning

猜你喜欢

转载自blog.csdn.net/xichengqc/article/details/90322245
今日推荐