We have a route that will accept the kafka.KEY and use that as mqtt url parameter to send the data to the right topic.
<routes
xmlns="http://camel.apache.org/schema/spring">
<route id="KafkaToMQTT">
<from uri="kafka://mqtt?brokers=localhost:9092"/>
<to uri="micrometer:timer:camel.proxy.kafka.mqtt.stream?action=start"/>
<log message="Headers ${header.kafka.KEY}"/>
<to uri="mqtt:mqtt?host=tcp://localhost:1883&publishTopicName=try${header.kafka.KEY}"/>
<to uri="log://camel.proxy?groupInterval=3&level=INFO"/>
<to uri="micrometer:timer:camel.proxy.kafka.mqtt.stream?action=stop"/>
</route>
</routes>
In the log messages I see the ${header.kafka.KEY} correctly, while in the mqtt I'm getting the topic as literally try${header.kafka.KEY}
What is the reason for that, how to make the header to be used there?
To avoid that the right element instead of to
should be used, that is toD
.
toD
concatenates the url correctly, so the right route XML is:
<routes
xmlns="http://camel.apache.org/schema/spring">
<route id="KafkaToMQTT">
<from uri="kafka://mqtt?brokers=localhost:9092"/>
<to uri="micrometer:timer:camel.proxy.kafka.mqtt.stream?action=start"/>
<log message="Headers ${header.kafka.KEY}"/>
<toD uri="mqtt:mqtt?host=tcp://localhost:1883&publishTopicName=ESP_02/try${header.kafka.KEY}"/>
<to uri="log://camel.proxy?groupInterval=3&level=INFO"/>
<to uri="micrometer:timer:camel.proxy.kafka.mqtt.stream?action=stop"/>
</route>
</routes>