Altova MobileTogether Designer

Actions on Message Received

Home Prev Top Next

After a solution has been subscribed to a topic at a broker, it will receive messages published by the broker under that topic. The message data (of the last message received) will be placed in the $MT_MQTT page source and can be accessed from there. The actions to be performed when a message is received is set on events at one of two levels: (i) an event at the page level for each page; (ii) an event at the solution (project) level (accessed via the Project Properties section of the Styles & Properties pane). If no event handling is defined on the page-level event of the active page, then the actions of the project-level event will be executed.

 

In this topic, we describe the following:

 

The $MT_MQTT page source

The events, one each at page and solution level, that are triggered when a message is received.

 

$MT_MQTT page source

The $MT_MQTT page source has the following fixed structure:

 

$MT_MQTT

Root

|-- Message

|      @topic

|      @content

 

At run time, if a solution has been subscribed to a topic at a broker, then that solution will receive messages published by the broker under that topic. The number of  message repeats received by the solution is determined by the the Quality of Service level specified in the subscription.

 

The latest message that is received will be placed in the $MT_MQTT page source, with the body of the message going into the $MT_MQTT/Root/Message/@content node and the topic name going into the $MT_MQTT/Root/Message/@topic node. The message data in the page source will now be accessible to the solution and can be used for data processing.

 

Note:The content of every received message is automatically converted by MobileTogether to a hexBinary string and stored in this format in the $MT_MQTT/Root/Message/@content node. In order to convert the hexBinary string to a text string, use the mt-hexBinary-to-string. MobileTogether provides two functions to convert between hexBinary strings and text strings: mt-hexBinary-to-string and mt-string-to-hexBinary.

 

Events triggered when a message is received

When a solution receives a message, the OnMQTTReceive event is triggered. You can specify what actions are to be performed when this event is triggered.

 

If OnMQTTReceive event actions have been defined at the page level, then these actions are executed when this page is active and receives a message.

If no OnMQTTReceive event action has been defined at the page level, then any OnMQTTReceive event actions defined at the project level will be executed.

 

This mechanism enables you to set actions at the project level, which can be triggered for any active page that does not have its own page-level OnMQTTReceive event actions.

 

© 2018-2024 Altova GmbH