Raj
Raj

Reputation: 1737

How Kafka producers manage the connections

I'm trying to understand how the producers make connections and maintain them when producing a message onto Kafka.

Let's say we have a kafka cluster with broker1, broker2 and broker3 and three producers producer1, producer2 and producer3.

Now let's assume all three producers are producing messages at t1, t1+10 sec , t1 + 20 sec respectively, I've below questions.

  1. If they are producing onto the same topic, will all of them use the same connection or each producer will have it's own connection?

  2. If they are producing onto three different topics, then how many connections would be open?

Upvotes: 3

Views: 1143

Answers (1)

OneCricketeer
OneCricketeer

Reputation: 192013

1) depends entirely on your code. You can reuse one producer object to send to any number of topics

2) depends how many partitions each topic has. You'll effectively have one connection per producer * the number of partitions that your partitioner has calculated

Test for yourself with netstat

Upvotes: 4

Related Questions