Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass topics dynamically to a kafka listener?

From a couple of days I'm trying out ways to dynamically pass topics to Kafka listener rather than using them through keys from a Java DSL. Anyone around done this before or could throw some light on what is the best way to achieve this?

like image 912
Vishal Mahuli Avatar asked Sep 25 '17 08:09

Vishal Mahuli


2 Answers

The easiest solution I found was to use SpEL:

@Autowired
private SomeBean kafkaTopicNameProvider;

@KafkaListener(topics = "#{kafkaTopicNameProvider.provideName()}")
public void listener() { ... }
like image 117
Gunslinger Avatar answered Oct 22 '22 03:10

Gunslinger


You cannot "dynamically pass topics to Kafka listener "; you have to programmatically create a listener container instead.

like image 28
Gary Russell Avatar answered Oct 22 '22 03:10

Gary Russell