Search code examples
springapache-kafkaspring-kafka

Is there a code sample for multiple producers in spring kafka?


I have an application that may need multiple producers. All code samples I see seem to support a single producer, reading config from app during app startup. If there are multiple producers and we want to pass in different producer config, is there out of the box support in Spring? Or should I just go without spring in that case?


Solution

  • You can create several Producer instances (KafkaTemplate) via the same ProducerFactory.

    If you need different Kafka configurations, you’ll need different ProducerFactory instances.