Altova MobileTogether Designer

Publish, Subscribe, Disconnect Broker

Home Prev Top Next

A MobileTogether solution can participate in an MQTT network as a publisher, a subscriber, or both. This topic describes the mechanisms that set up a solution as a publisher and as a subscriber, and it describes how to disconnect a solution from a broker.

 

Set up as a publisher

In order to publish an MQTT message to a broker, the solution will need the following information:

 

Information to connect to the broker

The topic under which a message will be published

The text of the message

 

You can specify this information in the Publish MQTT Message action (screenshot below), which is described in the Publish MQTT Message topic. Information for connecting to the broker is given in the Broker Address and Broker Port settings. The Topic and Message settings contain the other two important pieces of data needed to publish messages to the broker. If the connection is to be a secure connection, you will need to provide the additional information required to make the secure connection.

MTActionMQTTPublishMessage

At run time, when the Publish MQTT Message action is triggered (for example, on clicking a button in the solution), the solution will automatically attempt to connect to the broker. On connecting successfully, it will publish the message to the broker.

 

Set up as a subscriber

In order to subscribe to an MQTT topic at an MQTT broker, the solution will need the following information:

 

Information to connect to the broker

The topic to which you want to subscribe

The quality of service that you want for this subscription

 

You can specify this information in the Subscribe to MQTT action (screenshot below), which is described in the (Un)Subscribe to MQTT topic. Information for connecting to the broker must be given in the Broker Address and Broker Port settings. The topic you want to subscribe to is given in the Topic setting. You can specify the number of times individual messages should be delivered in the Quality of Service setting. If the connection is to be a secure connection, you will need to provide the additional information required to make the secure connection.

MTActionMQTTSubscribeToTopic

At run time, when this action is triggered (for example, when the page is loaded in the solution), the solution will automatically attempt to connect to the broker. On successfully connecting, it will receive new messages that were published under the subscribed topic. New messages will be received by the solution and placed in the solution's $MT_MQTT page source. If more than one message is available, then the messages are queued for placement in the $MT_MQTT page source. After the action handling for a received message has been completed, the next message in the queue will be placed in the $MT_MQTT page source and its action handling will be started.

 

Note:After a Subscribe action establishes a connection to a broker, the connection will be kept alive till it is explicitly disconnected (see next section below: Disconnect from broker). You should this in mind if your solution subscribes to a large number of brokers and topics.

 

Note:You can also unsubscribe from a topic subscription via the Unsubscribe to MQTT action. After the Unsubscribe action is executed, the solution will no longer receive messages about the topic from which it was unsubscribed.

 

Disconnect from broker

When the actions to publish or subscribe are started (see the description of the two actions above), the solution will automatically connect to the broker using the connection information you have given. The connection to the broker will be kept alive in both cases till explicitly disconnected via the Disconnect from Broker action. See the (Un)Subscribe to MQTT topic for details of this action.

 

© 2018-2024 Altova GmbH