为什么 kafka 生产者在初始化时采用代理端点而不是 zk [英] Why does kafka producer take a broker endpoint when being initialized instead of the zk

查看:23
本文介绍了为什么 kafka 生产者在初始化时采用代理端点而不是 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

推荐答案

我的生产者应该使用哪个代理?
我需要手动切换broker来平衡负载吗?

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"定义了生产者可以在哪里找到一个或多个 Broker 来确定每个主题的领导者.这不需要是集群中的全套 Broker,但应至少包括两个,以防第一个 Broker 不可用.无需担心找出哪个 Broker 是主题(和分区)的领导者,生产者知道如何连接到 Broker 并请求元数据,然后连接到正确的 Broker.

"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 端点,如果使用 Simple,则需要提供其他信息

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

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

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