kafaka学习

创建一个topic:

[root@hdp1 bin]# ./kafka-topics.sh --create --zookeeper hdp1:2181  --replication-factor 1 --partitions 1 --topic justin
Created topic "justin".
[root@hdp1 bin]# pwd
/usr/hdp/2.2.6.0-2800/kafka/bin

在zookeeper中可以查看到刚才创建的topic:

[zk: hdp1:2181(CONNECTED) 4] ls /brokers/topics
[topic1, ambari_kafka_service_check, , test, kafkaToptic]

由于在创建topic的时候,指定—partitions为1,所有在zookeeper中看到的分区数为一个:

[zk: hdp1:2181(CONNECTED) 7] ls /brokers/topics/justin/partitions
[0]
[zk: hdp1:2181(CONNECTED) 8] ls /brokers/topics/justin/partitions/0
[state]
[zk: hdp1:2181(CONNECTED) 9] ls /brokers/topics/justin/partitions/0/state
[]
[zk: hdp1:2181(CONNECTED) 10] ls /brokers/topics/justin/partitions/0      
[state]
[zk: hdp1:2181(CONNECTED) 11] ls /brokers/topics/justin/partitions/0/state
[]

kafka自带脚本也可以查看到zookeeper中创建的topic:

[root@hdp1 bin]# ./kafka-topics.sh --list --zookeeper hdp1:2181
ambari_kafka_service_check
justin
kafkaToptic
test
topic1

使用生产者,往kafka队列的justin主题(类似于bigpipe的pipe,partition和bigpipe的pipelet类似)发送两条消息:

[root@hdp1 bin]# ./kafka-console-producer.sh --broker-list hdp1:6667 --topic justin
justinzhang
This is another justin

使用消费者,从kafka队列的topic中获取消息,—from-beginning表示从开始处订阅:

[root@hdp1 bin]# ./kafka-console-consumer.sh --zookeeper hdp1:2181 --topic justin --from-beginning
justinzhang
This is another justin

可以使用将标准输入定位到文件的方式,往broker发送文件:

[root@hdp1 bin]# ./kafka-console-producer.sh --broker-list hdp1:6667 --topic justin < kafka-server-stop.sh

多个订阅者都可以收到生产者发送的消息。

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值