Reputation: 828
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
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