为什么在初始化卡夫卡生产者而不是zk时采取经纪人端点 [英] Why does kafka producer take a broker endpoint when being initialized instead of the zk

查看:71
本文介绍了为什么在初始化卡夫卡生产者而不是zk时采取经纪人端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有多个经纪人,我的生产者应使用哪个经纪人?我是否需要手动切换代理以平衡负载?还有,为什么消费者只需要一个Zookeeper端点而不是一个Broker端点?

If I have multiple brokers, which broker should my producer use? Do I need to manually switch the broker to balance the load? Also why does the consumer only need a zookeeper endpoint instead of a broker endpoint?

教程中的快速示例:

> bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test 
> bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning

推荐答案

我的生产者应该使用哪个经纪人?
是否需要手动切换代理以平衡负载?

which broker should my producer use?
Do I need to manually switch the broker to balance the load?

Kafka在集群(即节点集)上运行,因此在生成任何内容时,您需要告诉他为应用程序配置的代理的 LIST ,下面是从中摘录的内容文档.

Kafka runs on cluster, meaning set of nodes, so while producing anything you need to tell him the LIST of brokers that you've configured for your application, below is a small note taken from their documentation.

"metadata.broker.list"定义了生产者可以在哪里找到一个或多个经纪人来确定每个主题的负责人.这不必是集群中完整的代理集,但在第一个代理不可用的情况下,至少应包括两个代理.无需担心弄清楚哪个代理是该主题(和分区)的领导者,生产者知道如何连接到代理并请求元数据,然后连接到正确的代理.

"metadata.broker.list" defines where the Producer can find a one or more Brokers to determine the Leader for each topic. This does not need to be the full set of Brokers in your cluster but should include at least two in case the first Broker is not available. No need to worry about figuring out which Broker is the leader for the topic (and partition), the Producer knows how to connect to the Broker and ask for the meta data then connect to the correct Broker.

希望这能清除您的一些困惑

Hope this clear some of your confusion

为什么消费者只需要一个Zookeeper端点而不是一个经纪人端点

Also why does the consumer only need a zookeeper endpoint instead of a broker endpoint

从技术上讲,这是不正确的,因为有两种可用的API,高级和低级使用者.

This is not technically correct, as there are two types of APIs available, High level and Low level consumer.

高级使用者基本上会处理大多数事情,例如领导者检测,线程问题等,但是并不能提供对消息的太多控制,而这些消息正是使用其他替代方案简单或低级使用者的目的.将看到您需要提供与代理有关的分区详细信息.

The high level consumer basically takes care of most of the thing like leader detection, threading issue, etc. but does not provide much control over messages which exactly the purpose of using the other alternatives Simple or Low level consumer, in which you will see that you need to provide the brokers, partition related details.

因此,仅当您使用高级API时,消费者才需要Zookeeper端点,如果使用简单",则确实需要提供其他信息

So Consumer need zookeeper end point only when you are going with the high level API, in case of using Simple you do need to provide other information

这篇关于为什么在初始化卡夫卡生产者而不是zk时采取经纪人端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆