創(chuàng)建topic
創(chuàng)新互聯公司專注于源匯企業(yè)網站建設,成都響應式網站建設公司,商城建設。源匯網站建設公司,為源匯等地區(qū)提供建站服務。全流程按需網站制作,專業(yè)設計,全程項目跟蹤,創(chuàng)新互聯公司專業(yè)和態(tài)度為您提供的服務bin/kafka-topics.sh --create --zookeeper node02:2181 --replication-factor 1 --partitions 1 --topic test
kafka3.3.1新版本就會提示不兼容,需要改用新版本
Exception in thread "main" joptsimple.UnrecognizedOptionException: zookeeper is not a recognized option
at joptsimple.OptionException.unrecognizedOption(OptionException.java:108)
at joptsimple.OptionParser.handleLongOptionToken(OptionParser.java:510)
at joptsimple.OptionParserState$2.handleArgument(OptionParserState.java:56)
at joptsimple.OptionParser.parse(OptionParser.java:396)
at kafka.admin.TopicCommand$TopicCommandOptions.(TopicCommand.scala:567)
at kafka.admin.TopicCommand$.main(TopicCommand.scala:47)
at kafka.admin.TopicCommand.main(TopicCommand.scala)
bin/kafka-topics.sh --create --bootstrap-server node02:9092 --replication-factor 1 --partitions 1 --topic test
創(chuàng)建多分區(qū) 副本topic
bin/kafka-topics.sh --create --bootstrap-server node02:9092 --replication-factor 1 --partitions 2 --topic test
查看topic
bin/kafka-topics.sh --list --bootstrap-server node02:9092
查看指定topic信息
bin/kafka-topics.sh --describe --bootstrap-server node02:9092 --topic test
可以進入kafka的數據文件存儲目錄查看test和test1主題的消息日志文件:默認log目錄 /tmp/kafka-logs
消息日志文件主要存放在分區(qū)文件夾里的以log結尾的日志文件里,如下是test-1主題對應的分區(qū)0的消息日志:
leader節(jié)點負責給定partition的所有讀寫請求。
replicas 表示某個partition在哪幾個broker上存在備份。不管這個幾點是不是”leader“,甚至這個節(jié)點掛了,也會列出。
isr 是replicas的一個子集,它只列出當前還存活著的,并且已同步備份了該partition的節(jié)點。
刪除主題
bin/kafka-topics.sh --delete --topic test --bootstrap-server node02:9092
更新主題
bin/kafka-topics.sh -alter --partitions 1 --bootstrap-server node02:9092 --topic test
這個partition分區(qū)只能是增加分區(qū),不可以降低,否則報錯
Error while executing topic command : Topic currently has 2 partitions, which is higher than the requested 1.
[2022-12-03 20:45:18,531] ERROR org.apache.kafka.common.errors.InvalidPartitionsException: Topic currently has 2 partitions, which is higher than the requested 1.
參數 | 描述 |
---|---|
–bootstrap-server | 連接的 Kafka Broker 主機名稱和端口號。 |
–topic | 操作的 topic 名稱。 |
–create | 創(chuàng)建主題。 |
–delete | 刪除主題。 |
–alter | 修改主題 |
–list | 查看所有主題 |
–describe | 查看主題詳細描述 |
–partitions | 設置分區(qū)數 |
–replication-factor | 設置分區(qū)副本 |
–config | 更新系統默認的配置。 |
bin/kafka-console-producer.sh --broker-list node02:9092 --topic test
參數 | 描述 |
---|---|
–bootstrap-server | 連接的 Kafka Broker 主機名稱和端口號 |
–topic | 操作的topic |
bin/kafka-console-consumer.sh --bootstrap-server node02:9092 --topic test
如果想要消費之前的消息可以通過–from-beginning參數指定,如下命令:
bin/kafka-console-consumer.sh --bootstrap-server node02:9092 --from-beginning --topic test
消費多主題
bin/kafka-console-consumer.sh --bootstrap-server node02:9092 --whitelist "test|test-2"
同一個消費組下的消費者,只能有一個消費者消費到topic下的消息
設置消費組消息消息,單播消費
bin/kafka-console-consumer.sh --bootstrap-server node02:9092 --consumer-property group.id=testGroup --topic test
多播消費,如消費訂閱,不同消費組下的消費者可以消費同一topic下的同一條消息
bin/kafka-console-consumer.sh --bootstrap-server node02:9092 --consumer-property group.id=testGroup-2 --topic test
列出消費組列表
bin/kafka-consumer-groups.sh --bootstrap-server node02:9092 --list
查看消費組,消費信息的消費偏移信息
bin/kafka-consumer-groups.sh --bootstrap-server node02:9092 --describe --group testGroup
current-offset:當前消費組的已消費偏移量
log-end-offset:主題對應分區(qū)消息的結束偏移量(HW)
lag:當前消費組未消費的消息數
參數 | 描述 |
---|---|
–bootstrap-server | 連接的 Kafka Broker 主機名稱和端口號 |
–topic | 操作的 topic 名稱 |
–from-beginning | 從頭開始消費 |
–group | 指定消費者組名稱。 |
你是否還在尋找穩(wěn)定的海外服務器提供商?創(chuàng)新互聯www.cdcxhl.cn海外機房具備T級流量清洗系統配攻擊溯源,準確流量調度確保服務器高可用性,企業(yè)級服務器適合批量采購,新人活動首月15元起,快前往官網查看詳情吧
本文標題:Kafka-topicproducerconsumer常用命令-創(chuàng)新互聯
網頁鏈接:http://muchs.cn/article10/dhedgo.html
成都網站建設公司_創(chuàng)新互聯,為您提供網站收錄、電子商務、微信公眾號、響應式網站、移動網站建設、網站策劃
聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯