1. 程式人生 > >kafka基本命令啟動和測試

kafka基本命令啟動和測試

Step 1: 啟動伺服器

首先啟動zookeeper

> bin/zookeeper-server-start.sh config/zookeeper.properties
(遠端啟動的時候需要在後面加上一個 & 作為後臺程序,然後斷開和遠端的連結)

接著啟動kafka伺服器

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

Step 2: 建立 一個 topic

> bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test

檢視topic

> bin/kafka-topics.sh --list --zookeeper localhost:2181

Step 3: Send some messages

> bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test 
This is a message
This is another message

Step 4: 啟動一個客戶端(消費者)

> bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning