How to control which MQTT topics the mappers subscribe to
The cloud-specific mappers subscribe to the reserved MQTT topics and convert incoming MQTT messages to cloud-specific messages. In an advanced use case, such as using more than one cloud mappers for the same device, you may want to customize the external tedge MQTT topics that each cloud mapper subscribes to.
The tedge config
command and the keys c8y.topics
, az.topics
, and aws.topics
are usable for this use-case.
Cloud | tedge config key | Environmental variable | systemctl service |
---|---|---|---|
Cumulocity IoT | c8y.topics | TEDGE_C8Y_TOPICS | tedge-mapper-c8y |
Azure IoT | az.topics | TEDGE_AZ_TOPICS | tedge-mapper-az |
AWS IoT | aws.topics | TEDGE_AWS_TOPICS | tedge-mapper-aws |
This guide uses c8y.topics
, TEDGE_C8Y_TOPICS
, and tedge-mapper-c8y
as an example.
For other cloud mappers, use the keys in the table.
Check the subscribed MQTT topics​
First, check which MQTT topics are subscribed by a cloud mapper. Run:
tedge config get c8y.topics
["te/+/+/+/+", "te/+/+/+/+/twin/+", "te/+/+/+/+/m/+", "te/+/+/+/+/e/+", "te/+/+/+/+/a/+", "te/+/+/+/+/status/health"]
Set the desired new MQTT topics​
If you want to change the subscribed MQTT topics, use tedge config set
.
For example, if you want the Cumulocity IoT mapper to subscribe only to te/+/+/+/+/m/+
and te/+/+/+/+/a/+
topic,
the command to run should be as below.
sudo tedge config set c8y.topics te/+/+/+/+/m/+,te/+/+/+/+/a/+
Alternatively, the same setting can be controlled via environment variables. The environment variable settings will override any values set by the tedge config command.
export TEDGE_C8Y_TOPICS=te/+/+/+/+/m/+,te/+/+/+/+/a/+
If an invalid MQTT topic is given, the mapper will ignore it.
The service must be restarted for the setting to take effect. The following command shows how to restart the Cumulocity IoT mapper on a device using systemd as the init system.
sudo systemctl restart tedge-mapper-c8y
Change back to the default topics​
If you want a mapper to subscribe back to the default MQTT topics, run:
sudo tedge config unset c8y.topics
Then restart the corresponding mapper.