查看已有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能夠經過list命令查看建立的topic:> bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 2 --topic hawkeyes-vest
12> bin/kafka-topics.sh --list --zookeeper localhost:2181test除了手動建立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-vestctrl+c能夠退出發送;啓動ConsumerKafka also has a command line consumer that will dump out messages to standard output.Kafka也有一個命令行consumer能夠讀取消息並輸出到標準輸出:1234>bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic hawkeyes-vest --from-beginningThis is a messageThis is another message12你在一個終端中運行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