broker-list
broker指的是kafka的服務端,可以是一個服務器也可以是一個集群。producer和consumer都相當於這個服務端的客戶端。
broker-list指定集群中的一個或者多個服務器,一般我們再使用console producer的時候,這個參數是必備參數,另外一個必備的參數是topic,如下示例:
C:\kafka\kafka_2.12-1.1.1 λ .\bin\windows\kafka-console-producer.sh --broker-list localhost:9092 --topic test >this is a test
本地主機如果要模擬多個broker,方法是復制多個server.properties,然后修改里面的端口, broker.id等配置模擬多個broker集群。
bootstrap-servers vs zookeeper
bootstrap-servers指的是目標集群的服務器地址,這個和broker-list功能是一樣的,只不過我們在console producer要求用后者。
以前我們使用console consumer測試消息收發時會這樣寫:
C:\kafka\kafka_2.12-1.1.1 λ .\bin\windows\kafka-console-consumer.sh --zookeeper localhost:2181 --topic test
Using the ConsoleConsumer with old consumer is deprecated and will be removed in a future major release. Consider using the new consumer by passing [bootstrap-server] instead of [zookeeper].
這樣可以接收到生產者控制台發送的消息。
現在我們也可以這樣寫,
C:\kafka\kafka_2.12-1.1.1 λ .\bin\windows\kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test
你可以自己測試下,也是可以收到消息的。
前者是老版本的用法,0.8以前的kafka,消費的進度(offset)是寫在zk中的,所以consumer需要知道zk的地址。這個方案有性能問題,0.9 的時候整體大改了一次,brokers 接管了消費進度,consumer 不再需要和 zookeeper 通信了,所以就用bootstrap-server了。
新版的 Kafka 使用一個選舉出來的 controller 來監聽 zookeeper,其他 node 再去和 controller 通信,這么做的目的是為了減少 zookeeper 的壓力。bootstrap-servers 會自動發現其他 broker,這也是 bootstrap 的含義


參考原文鏈接:https://blog.csdn.net/pony_maggie/article/details/95862515