Relay MQTT messages between client devices and AWS IoT Core
You can relay MQTT messages and other data between client devices and AWS IoT Core. Client devices connect to the MQTT broker component that runs on the core device. By default, core devices don't relay MQTT messages or data between client devices and AWS IoT Core. Client devices can communicate only with each other over MQTT by default.
To relay MQTT messages between client devices and AWS IoT Core, configure the MQTT bridge component to do the following:
-
Relay messages from client devices to AWS IoT Core.
-
Relay messages from AWS IoT Core to client devices.
Note
The MQTT bridge uses QoS 1 to publish and subscribe to AWS IoT Core, even when a client device uses QoS 0 to publish and subscribe to the local MQTT broker. As a result, you might observe additional latency when you relay MQTT messages from client devices on the local MQTT broker to AWS IoT Core. For more information about MQTT configuration on core devices, see Configure MQTT timeouts and cache settings.
Configure and deploy the MQTT bridge component
The MQTT bridge component consumes a list of topic mappings that each specify a message source and a message destination. To relay messages between client devices and AWS IoT Core, deploy the MQTT bridge component, and specify each source and destination topic in the component configuration.
To deploy the MQTT bridge component to a core device
or group of core devices, create a deployment that
includes the aws.greengrass.clientdevices.mqtt.Bridge
component. Specify the topic
mappings, mqttTopicMapping
, in the MQTT bridge component configuration in the
deployment.
The following example defines a deployment that configures the MQTT bridge component to
relay messages on topics that match the clients/+/hello/world
topic filter from
client devices to AWS IoT Core. The merge
configuration update requires a serialized
JSON object. For more information, see Update component configurations.
Relay MQTT messages
To relay MQTT messages between client devices and AWS IoT Core, configure and deploy the MQTT Bridge component and specify the topics to relay.
Example: Relay messages on a topic from client devices to AWS IoT Core
The following MQTT bridge component configuration specifies relaying messages on topics
that match the clients/+/hello/world/event
topic filter from client devices to
AWS IoT Core.
{ "mqttTopicMapping": { "HelloWorldEvent": { "topic": "clients/+/hello/world/event", "source": "LocalMqtt", "target": "IotCore" } } }
Example: Relay messages on a topic from AWS IoT Core to client devices
The following MQTT bridge component configuration specifies relaying messages on topics
that match the clients/+/hello/world/event/response
topic filter from AWS IoT Core
to client devices.
{ "mqttTopicMapping": { "HelloWorldEventConfirmation": { "topic": "clients/+/hello/world/event/response", "source": "IotCore", "target": "LocalMqtt" } } }