VKR
VKR

Reputation: 339

KafkaListener mulitple topics in yaml file

I want to read from multiple topics, so i declared them in yaml file with comma separated but getting below error:

java.lang.IllegalStateException: Topic(s) [ topic-1 , topic-2, topic-3, topic-4, topic-5, topic-6, topic-7] is/are not present and missingTopicsFatal is true

Spring:
  kafka:
    topics:
      tp: topic-1 ,  topic-2,  topic-3,  topic-4,  topic-5,  topic-6, topic-7
@KafkaListener(topics = "#{'${spring.kafka.topics.tp}'.split(',')}",
        concurrency = "190",
        clientIdPrefix = "client1",
        groupId = "group1")
public void listenData(final ConsumerRecord<Object, Object> inputEvent) throws Exception {
    handleMessage(inputEvent);
}

if i declare all topics inside KafkaListener annotation its working fine.

Upvotes: 1

Views: 1430

Answers (1)

Gary Russell
Gary Russell

Reputation: 174544

Remove the spaces

tp: topic-1,topic-2,topic-3,topic-4,topic-5,topic-6,topic-7

Or use

.split(' *, *')

Upvotes: 1

Related Questions