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?
Asked
Active
Viewed 1,799 times
3

stefanobaghino
- 11,253
- 4
- 35
- 63

preetham
- 738
- 1
- 8
- 15
-
2Possible duplicate of [Kafka Producer - By default supports Multithreading?](https://stackoverflow.com/questions/28540425/kafka-producer-by-default-supports-multithreading) – Valentin Michalak Jan 06 '18 at 01:32
1 Answers
6
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.

Mikita Harbacheuski
- 2,193
- 8
- 16
-
If I am pushing data from database to Kafka Producer to two different topics, how to achieve sending messages from same database simultaneously to two different topics ? – preetham Jan 09 '18 at 00:17
-