kafka基礎知識點
1、安裝:
1.1. 前置安裝要求:java + zookeeper
1.2. 下載安裝包:http://mirros.cnnic.cn/apache/kafka/0.9.00/kafka_2.10-0.9.0.0.tgz
1.3. 執行安裝命令:kafka-server-start.sh ../config/server.properties &
2、基本組件
2.1 Producer: 消息生產者
2.2 Consumer: 消費消費者
2.3 Broker:一臺kafka服務器被稱為一個broker,整個集群可由多個 Broker組成
2.4 Partition:一個Topic在物理上可以劃分為多個Partition,每個Partition可以理解為獨立的物理隊列(文件載體),
該Partition可以被負載到不同的Broker上實現Kafka的水平擴展;
2.5 Topic:消息隊列

3、常用的命令
3.1 創建一個topic
./kafka-topics.sh --zookeeper localhost:2181 --create --topic test01 --partitions 3 --replication-factor 1
3.2 查看當前所有的topic
./kafka-topics.sh --zookeeper localhost:2181 --list
3.3 在控制臺啟動一個生產者
./kafka-console-producer.sh --broker-list localhost:9092 --topic test01
3.4 在控制臺啟動一個消費者
./kafka-console-consumer.sh --zookeeper localhost:2181 --topic test01 --from-beginning
3.5 啟動一個消費者并制定消費者組
./kafka-console-consumer.sh --consumer.config ../config/consumer.properties --zookeeper localhost:2181 --topic test01 --from-beginning
在consumer.properties中設置消費者組,一個消費者組可以包含多個消費者
#consumer group id
group.id=tg
3.6 查看某個topic的消費進度,必須以消費者組為單位
./kafka-run-class.sh kafka.tools.ConsumerOffsetChecker --group tg01 --zookeeper localhost:2181

如上例,不同的消費者組對于用一個topic,讀的進度(偏移)是不一樣的
3.7 查看topic詳情
./kafka-topics.sh --describe --zookeeper localhost:2181 --topic test02

浙公網安備 33010602011771號