注意事項:git
問題1:github
根據kafka官網操做進行消費消息,命令:bin/kafka-console-consumer.sh --bootstrap-server 192.168.0.239:9092 --topic test --from-beginning,KafkaOffsetMonitor提示找不到激活的消費者,其實消費者一直存活,沒法監控到消費的offset狀態。spring
緣由:KafkaOffsetMonitor是基於ZooKeeper進行的offset管理,--bootstrap-server 方式沒有經過ZooKeeper,KafkaOffsetMonitor沒法管理。bootstrap
解決方式:springboot
1.將命令修改成:bin/kafka-console-consumer.sh --zookeeper 192.168.0.239:2181 --topic test2 --from-beginningserver
2.或者另一個版本嘗試,地址:https://github.com/Morningstar/kafka-offset-monitor,本人何嘗試事件
問題2:get
kafka客戶端版本問題:kafka
說明:it
0.9.0.x以前,kafka消費端都是scale編寫,kafka有高階API和低階API之分。
高階API特色:簡單省事,只能從以前消費的地方繼續消費,除非本身重置offset。
低階API特色:靈活麻煩,能夠指定offset從任意位置消費。
0.9.0.x版本以後,消費端高階與低階API已經整合到一塊兒,分別對應subscribe和assign方法。
具體實現代碼:
高階API實現代碼,支持事件訂閱模式,消費kafka消息:
https://github.com/zhangzaixing/eddue-jms
還有一個springboot的版本kafka支持簡易實現: