preetham
preetham

Reputation: 828

Sharing Kafka producer between threads

Is it possible to have single instance of a Kafka producer shared between multiple threads to send messages to multiple topics? Is there any concurrency issue I might want to be aware of before?

Upvotes: 3

Views: 2205

Answers (1)

Mikita Harbacheuski
Mikita Harbacheuski

Reputation: 2253

According to the KafkaProducer documentation

The producer is thread safe and sharing a single producer instance across threads will generally be faster than having multiple instances.

So yes, it's perfectly valid and even recommended to share a single producer between multiple threads.

Upvotes: 7

Related Questions