MQTT Example(4.0)
This section contains one example for the MQTT agent.
Â
MQTT workflow example
In the above example, the MQTT agent sends any of these 3 UDR types: Error, PublishAck or SubscribeResponse to the Analysis agent, which contains the following code:
consume { Â Â Â debug(input); Â Â Â if(instanceOf(input, MQTT.SubscribeResponse)){ Â Â Â Â Â Â Â MQTT.SubscribeResponse resp = (MQTT.SubscribeResponse)input; Â Â Â Â Â Â Â MQTT.Publish pub = udrCreate(MQTT.Publish);Â Â Â Â Â Â Â Â Â pub.qos = 1; Â Â Â Â Â Â Â pub.retain = true; Â Â Â Â Â Â Â pub.topic = "test/"; Â Â Â Â Â Â Â pub.data = resp.data; Â Â Â Â Â Â Â udrRoute(pub); Â Â Â } }
With this code, the Analysis agent will:
- Debug the output of the MQTT agent.
- If the received UDR is of the SubscriberResponse type, the UDR will be populated into a SubscribeResponse type UDR called resp.
- Create a UDR of Publish type called pub.
- Set the qos to 1, to indicate that the message will be publish with the At Least once QoS.
- Set retain to true.
- Set the topic to test/
- Populate the Data with the Data field from the resp UDR.
Routes the pub UDR back to the MQTT agent.