kafka常見命令

基礎命令

查看已有topic併發

進入kafka解壓目錄:/home/zallds/kafka_2.10-0.10.2.1ide

執行以下命令,就會列出全部topicspa

[zallds@PUBLIC-26 bin]$ bin/kafka-topics.sh -list -zookeeper localhost:2181
hawkeyes-vest命令行

 

啓動kafka服務server

1.kafka用到了zookeeper,因此先啓動zookeeperkafka

    >bin/zookeeper-server-start.sh config/zookeeper.properties &it

2.啓動kafkaio

    >bin/kafka-server-start.sh config/server.propertiesconsole

 

建立topicclass

建立一個叫作「test」的topic,它只有一個分區,一個副本。
 
1
 
 
 
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication
     -factor --partitions --topic hawkeyes-vest
 
 
能夠經過list命令查看建立的topic:
 
1
2
 
 
 
bin/kafka-topics.sh --list --zookeeper localhost:2181
test 
 
 
除了手動建立topic,還能夠配置broker讓它自動建立topic.
 
刪除分區
>bin/kafka-topics.sh  --delete --zookeeper  localhost:2181  --topic hawkeyes-vest
 
發送消息
Kafka 使用一個簡單的命令行producer,從文件中或者從標準輸入中讀取消息併發送到服務端。默認的每條命令將發送一條消息。

運行producer並在控制檯中輸一些消息,這些消息將被髮送到服務端:
>bin/kafka-console-producer.sh --broker-list localhost:9092 --topic hawkeyes-vest
ctrl+c能夠退出發送;
 
 
啓動Consumer
 
Kafka also has a command line consumer that will dump out messages to standard output.
Kafka也有一個命令行consumer能夠讀取消息並輸出到標準輸出:
 
1
2
3
4
 
 
 
>bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic hawkeyes
     -vest --from-beginning
This is message
This is another message
 
 
 
 
1
2
 
 
 
行consumer行producer
    
 
 
 
這兩個命令都有本身的可選參數,能夠在運行的時候不加任何參數能夠看到幫助信息。
 
 
消費消息
 
>bin/kafka-console-consumer.sh -- zookeeper localhost:2181 --from-beginning --topic hawkeyes-vest
 
 
查看topic:hawkeyes-vest的分區狀況
bin/kafka-topics.sh --zookeeper localhost:2181 --topic hawkeyes-vest
相關文章
相關標籤/搜索