Ahmad Alhilal
Ahmad Alhilal

Reputation: 454

Can we assign a source port for Kafka Producer?

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.

Upvotes: 0

Views: 749

Answers (2)

Robin dubey
Robin dubey

Reputation: 1

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_castRdKafka::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.

Upvotes: 0

OneCricketeer
OneCricketeer

Reputation: 191904

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

Upvotes: 1

Related Questions