1

I have a toml file being used to configure an application that uses Spring framework's KafkaListener annotation with the following signature:

@KafkaListener(id = "id0", topics = "some.hard.coded.topic.name")

I have a configuration manager class that reads a TOML file and configures various application settings based on the environment the app is running in. One of these is the topic to listen to. However, I do not know how I can pass this in to the Kafka Listener annotation. My understanding is that this can be done using SPEL in conjunction with yml files but I'm kind of locked in to using TOML here. Can anyone advise?

4

1 回答 1

2

The topics property of the @KafkaListener indeed supports a SpEL including BeanFactory access, so if you have some bean which reads that TOML file and represents it as some set of runtime properties, e.g. getters, then you definitely can get a gain of the SpEL there. For example:

topics = "#{myTomlService.getTopic()}"

where myTomlService is a bean name for the mentioned service.

于 2018-10-15T20:05:05.140 回答