創(chuàng)建 Kafka Topic
bin/kafka-topics.sh --zookeeper node01:2181 --create \
--topic golang --partitions 30 --replication-factor 2
注: partitions指定topic分區(qū)數(shù),replication-factor指定topic每個(gè)分區(qū)的副本數(shù)
partitions分區(qū)數(shù):
- partitions :分區(qū)數(shù),控制topic將分片成多少個(gè)log。可以顯示指定,如果不指定則會(huì)使用broker(server.properties)中的num.partitions配置的數(shù)量
- 雖然增加分區(qū)數(shù)可以提供kafka集群的吞吐量、但是過多的分區(qū)數(shù)或者或是單臺(tái)服務(wù)器上的分區(qū)數(shù)過多,會(huì)增加不可用及延遲的風(fēng)險(xiǎn)。因?yàn)槎嗟姆謪^(qū)數(shù),意味著需要打開更多的文件句柄、增加點(diǎn)到點(diǎn)的延時(shí)、增加客戶端的內(nèi)存消耗。
- 分區(qū)數(shù)也限制了consumer的并行度,即限制了并行consumer消息的線程數(shù)不能大于分區(qū)數(shù)
- 分區(qū)數(shù)也限制了producer發(fā)送消息是指定的分區(qū)。如創(chuàng)建topic時(shí)分區(qū)設(shè)置為1,producer發(fā)送消息時(shí)通過自定義的分區(qū)方法指定分區(qū)為2或以上的數(shù)都會(huì)出錯(cuò)的;這種情況可以通過alter –partitions 來增加分區(qū)數(shù)。
replication-factor副本
- replication factor 控制消息保存在幾個(gè)broker(服務(wù)器)上,一般情況下等于broker的個(gè)數(shù)。
- 如果沒有在創(chuàng)建時(shí)顯示指定或通過API向一個(gè)不存在的topic生產(chǎn)消息時(shí)會(huì)使用broker(server.properties)中的default.replication.factor配置的數(shù)量
查看group列表
bin/kafka-consumer-groups.sh --bootstrap-server kafka1.irybd.com:9092 \
--groups --list
查看group 的topic 消費(fèi)情況
$ bin/kafka-consumer-groups.sh --bootstrap-server kafka1.irybd.com:9092 \
--group test-consumer-group --describe
Note: This will not show information about old Zookeeper-based consumers.
Consumer group 'test-consumer-group' has no active members.
TOPIC PARTITION CURRENT-OFFSET LOG-END-OFFSET LAG CONSUMER-ID HOST CLIENT-ID
crawler-media 0 17414248 24371857 6957609 - - -
TOPIC : TOPIC名字
PARTITION: 分區(qū)ID
CURRENT-OFFSET: 當(dāng)前偏移量,目前消費(fèi)到哪里
LOG-END-OFFSET: 結(jié)束偏移量,總共有多少數(shù)據(jù)
LAG: 還剩多少?zèng)]有消費(fèi)