How to use ${...} in Camel K Kafka URL?

175 views Asked by At

I have saved topic in header and try to access it in the Kafka URL as below:

from(...)
.process(...)
.to("kafka:${header.topic}?brokers=localhost:9092")

Unfortunately it says the Kafka URL is invalid:

org.apache.kafka.common.errors.InvalidTopicException: Invalid topics: [${header.topic}]

I have tried replace the to(...) with .log("${header.topic}") and the expected value can be printed in the logline.

Does anyone know what causes the issue, am I supposed to escape the dollar sign or the curly braces?

2

There are 2 answers

1
Luca Burgazzoli On BEST ANSWER

you need to use send dynamic so replace to with toD

1
erayerdem On

The header body and property values are dynamic values and can take a different value each time the stream triggers. You have to specify this to the camel and toD method do this.