我们可以为Kafka生产者分配一个源端口吗?

huangapple go评论63阅读模式
英文:

Can we assign a source port for Kafka Producer?

问题

我注意到 Kafka 生产者使用了 TCP 协议。

有没有办法预先固定多个 Kafka 生产者的源端口?
或者至少,有没有办法我可以追踪 Kafka 生产者的源端口?
我需要追踪 Kafka 生产者和消费者的带宽。
并且需要根据这些端口设置流量控制 (tc) 规则。

英文:

I noticed that Kafka Producer uses tcp protocol.

Is there any way to fix the source ports of the multiple Kafka producers in advance?
Or at least, Is there any way I can track the source port of Kafka producer?
I need to track the bandwidth of kafka producers and consumers.
And need to set up traffic control (tc) rules according to these ports.

答案1

得分: 1

制造商不会打开入站socket,因此没有绑定“源端口”。

您必须提供的唯一网络信息是 bootstrap.servers

英文:

Producers don't open inbound sockets, so there is no binding of a "source port".

The only network information you must provide is bootstrap.servers

答案2

得分: 0

为了实现这一点,您可以在 librdKafka 库中使用一个称为 socket_cb() 的东西(我使用的是 2.0.2 版本)。为了达到这个目的,您需要进行以下设置:

Rdkafka::Conf* globalConf = Rdkafka::Conf::create(Rdkafka::Conf::CONF_GLOBAL);

globalConf->set("socket_cb", static_cast<RdKafka::EventCb*>(this), errstr);

然后,重新编写 socket_cb() 函数:

  1. 调用 getaddrinfo() 函数,获得地址结构列表。
  2. 使用 socket() 函数获取文件描述符(FD)。
  3. 将选定的 FD 绑定(bind)。

这应该可以解决上述问题。

英文:

To achieve this you can use something called a socket_cb() in librdKafka library
(I was using 2.0.2 version).
To achieve this u need to set

Rdkadka::Conf* globalConf = Rdkafka::Conf::create(Rdkafka::Conf::CONF_GLOBAL)

globalConf->set("socket_cb", static_cast<RdKafka::EventCb*>(this), errstr);

And now rewrite the socket_cb() function

  1. getaddrinfo() //gives list of address structure
  2. socket() to get the the FD
  3. bind to the selected FD

this should solve the above issue.

huangapple
  • 本文由 发表于 2020年9月22日 21:22:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/64010696.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定