Reputation: 1643
I'm currently working on my first SpringXD Stream. It should receive a message on an MQTT topic, do a HTTP POST on a service and publish this result on another MQTT topic.
Currently I'm stuck at publishing to a different MQTT topic than the initial one.
This is my stream:
stream create test --definition "in:mqtt --url='tcp://hivemq:1883' --topics='+/+/+/my/downlink' --username='test' --password='test' --clientId='client_downlink'
| header-enricher --headers={\"mqtt_topic\":\"headers['mqtt_topic'].replace('/downlink', '/uplink')\"}
| out:mqtt --url='tcp://hivemq:1883' --username='test' --password='test' --clientId='client_uplink'" --deploy
The approach is to replace "/downlink" by "/uplink" in the header 'mqtt_topic' for Publishing but header-enricher doesn't overwrite existing header values, so the publish is made on the same topic as we received the message.
Any Idea how I could achieve this?
Upvotes: 1
Views: 129
Reputation: 1723
I am working on an enhancement for this. Meanwhile you can edit the header-enricher groovy script modules/processor/header-enricher/config/header-enricher.groovy
and make this change:
si.'header'(name:k,expression:v,overwrite:true)
Upvotes: 3