Sumit
Sumit

Reputation: 671

Create consumer dynamically spring kafka

I am creating a service which talks to another service in order to identify kafka topics to be listened to. The kafka topics may have different key and value types. Hence, I want to dynamically create different kafka consumers for each configuration(topic, key type, value type) where the configurations are known only at runtime. However in spring kafka, I don't see ways to pass all these parameters dynamically(at least I am not aware of any). How should I go ahead with this.

Upvotes: 2

Views: 15947

Answers (1)

Gary Russell
Gary Russell

Reputation: 174759

Simply create a new listener container at runtime.

https://docs.spring.io/spring-kafka/reference/kafka/receiving-messages/message-listener-container.html

If you are using Spring Boot, you can use the ConcurrentKafkaListenerContainerFactory that it automatically configures, to create containers; if not, just create and initialize the containers manually.

Upvotes: 4

Related Questions