天天看點

kafka的一些基本操作

一、檢視topic的指令

kafka的一些基本操作

二、測試

2.1啟動生産者

2.2 啟動消費者

./kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
           

三、啟動zookeeper

四。啟動kafka

來看下實驗:

kafka的一些基本操作

你在左邊執行生産者,在右邊就會自動顯示消費者。兩者相輔相成。

#在本機建立kafka,副本數量為1,分區數量為1
[[email protected] bin]# ./kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic test
#檢視本機的topic
[[email protected] bin]# ./kafka-topics.sh --list --bootstrap-server localhost:9092
test
#發送消息到test
[[email protected] bin]# ./kafka-console-producer.sh --broker-list localhost:9092 --topic test
>aaa
>bbb
>ccc
#開啟新的終端,進行讀取消息測試,“--from-beginning”表示從開頭讀取
[[email protected] bin]# ./kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
aaa
bbb
ccc
           

通過神策平台訂閱資料

cd  /sensorsdata/metadata/sa_cluster/cloudera/parcels/KAFKA-2.2.0-1.2.2.0.p0.68/lib/kafka/bin

./kafka-console-consumer.sh --bootstrap-server xxxx:9092 --topic event_topic