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

  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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值