Network nodes¶
Network palette consists of "mqtt in" and "mqtt out" nodes. "mqtt in" node connects to an MQTT broker and subscribes to messages from the specified topic. "mqtt out" node connects to an MQTT broker and publishes messages. The important terms in the MQTT telemetry protocol are described below.
Note
- Use MQTT nodes for productive use cases only or you can connect with connectivity features. For more information on Connectivity, refer to Connectivity.
- These MQTT nodes are used with some limitations. For more information on limitations, refer to Technical specifications.
- MQTT is now enabled for subtenants also.
- MQTT nodes are not available for Region Europe 2 and for private deployment options.
MQTT message¶
A message with MQTT consists of several parts:
- A defined subject ("Topic")
- An assigned criterion for "Quality of Service"
- The message text
MQTT Client¶
An MQTT Client is a program or device that uses MQTT. A client always actively establishes the connection to the broker. A client can perform the following functions:
- Send messages with a defined subject ("Topic"), in which other clients might be interested, to the MQTT Broker (Publish mechanism)
- Subscribe messages which follow a certain topic (Subscriber mechanism) at the MQTT Broker
- Unsubscribe yourself from subscribed messages
- Disconnect from the broker
On-boarding process¶
To onboard MQTT client, follow these steps:
-
In Visual Flow Creator, click and select "MQTT Management"
-
Create the credentials for the client.
- Enter the credentials from the client side.
- Credential limitations: Username begin with
in MQTT User Management. - Client ID starts with
that could be selected by user.
- Credential limitations: Username begin with
Note
- Adhere with all the client's unique identifiers to connect with the client.
- Only Visual Flow Creator admin can use "MQTT User Management" page.
MQTT Broker¶
An MQTT Broker is the central component of MQTT and can be a program or a device. The MQTT Broker acts as an intermediary between the sending MQTT Client and the subscribing MQTT Client. The MQTT Broker manages the topics including the messages contained therein and regulates the access to the topics. The MQTT Broker has the following functions:
- Accept network connections from the MQTT Clients
- Receive messages from an MQTT Client
- Edit subscription requests from MQTT Clients
- Forward messages to the MQTT Clients that match your subscription
Note
Visual Flow Creator provides you the own MQTT broker with address
Topics¶
MQTT messages are organized in topics. A topic "describes" a subject area. The topics can be subscribed to by the MQTT Clients (subscriber mechanism). The sender of a message (Publisher mechanism) is responsible for defining content and topic when sending the message. The broker then takes care that the Subscribers get the news from the subscribed topics. The topics follow a defined scheme. They are similar to a directory path and represent a hierarchy.
Note
The client can only subscribe on the topics and publish the topics that starts from vfc/
MQTT ports¶
MQTT defines an OASIS or ISO standard (ISO/IEC PRF 20922). Depending on the protocols used, MQTT runs on different access ports. Visual Flow Creator offers the following ports:
8883: MQTT, encrypted
443: MQTT via WebSockets, encrypted
Architecture¶
The MQTT is a publish and subscribe protocol. This mechanism decouples a client sending messages (Publishers) from one or more clients receiving the messages (Subscribers). This also means that the "Publishers" know nothing about the existence of the "Subscribers" (and vice versa). There is a third component in the MQTT architecture, the MQTT Broker. The MQTT Broker is located between "Publisher" and "Subscriber". The MQTT Broker controls the communication.
Quality of Service (QoS)¶
The MQTT specification provides three service qualities for message transmission quality assurance:
- QoS "0": The lowest level 0 is a "fire'n'forget" method. This means that there is no guarantee that the message will arrive at all.
- QoS "1": The QoS level 1 ensures that the message ends up in the topic queue at least once. The MQTT Broker acknowledges receipt of the message.
- QoS "2": In the highest level 2, the MQTT Broker guarantees by multiple handshake with the MQTT Client that the message is exactly filed once.
Last will¶
MQTT supports the "Last Will and Testament" feature. This feature is used to notify other MQTT Clients if the connection to a MQTT Client has been disconnected accidentally.
Each MQTT Client can specify its last will while connecting to the MQTT Broker and notify the MQTT Broker. This last will is built like a normal MQTT message, including topic, QoS and payload. The MQTT Broker saves the last will. As soon as the MQTT Broker notices that the connection with the MQTT Client in question has been abruptly terminated, the MQTT Broker sends the last will as an MQTT message to all subscribers who have registered for the topic. In this way, the subscribers also learn that the MQTT Client has been disconnected.
Keep-Alive¶
MQTT supports the "Keep-Alive" feature. This ensures that the connection is still open and the MQTT Client and MQTT Broker are connected.
For the Keep-Alive, the MQTT Clients define a time interval and communicate it to the MQTT Broker during their connection setup. This interval is the largest possible tolerated time period in which the MQTT Client and the MQTT Broker may remain without contact. If the time is exceeded, the MQTT Broker must disconnect.
That means that, as long as the MQTT Client periodically sends messages to the broker within the Keep-Alive interval, the MQTT Client does not need to take any special action to maintain the connection. However, if the MQTT Client does not send any messages within the Keep-Alive interval, they must ping the MQTT Broker before the deadline expires. With this ping, the MQTT Client signals to the MQTT Broker that it is still available.
When a message or a ping packet has been sent to the MQTT Broker, timing for the Keep-Alive interval begins again.
Message persistence¶
If the connection to an MQTT Client is interrupted, the broker can cache new messages for this client for later delivery.
Retained messages¶
The first time an MQTT Client subscribes to a topic, it usually gets a message only when another MQTT Client sends a message with the subscribed topic the next time. With "Retained messages", the subscriber receives the last value sent to the topic prior to its subscription request, delivered immediately.
The "network" nodes and their respective functions in Visual Flow Creator are described in the following sections:
Mqtt in node¶
The "mqtt in" node allows you to subscribe to the specified topic.
Mqtt out node¶
The "mqtt out" node allows you to publish the messages to MQTT broker. The following properties are available for MQTT5 and Visual Flow Creator supports MQTT5.
Node property | Description |
---|---|
User Properties | It allows to appear multiple times to represent multiple names and value pairs in the "Object" format |
Response topic | It is used as the topic name for a response message in the "String" format |
Correlation Data | It is used to identify the Response Message as per the "Request Message" received in the "String" format |
Content Type | It describes the content of the application message in the following formats: - application/json - application/octet-stream - text/csv - text/html - text/plain - other |
Expiry (secs) | It is the process time of the application message in seconds |
Using mqtt in node¶
To subscribe the messages from the specified topic using mqtt in node, follow these steps:
-
From the node palette, drag and drop the "mqtt in" node from the network palette and two "debug" nodes from the output palette to the working area. Connect the nodes in a flow as shown below:
-
Double click on "mqtt in" node to edit the properties.
- Enter the "Topic".
- In the output section, you can select any one of the following options from the dropdown menu.
- Enter the "Name".
- Click "Done".
Note
The subscription topic can include MQTT wildcards, "+" for one level, "#" for multiple levels.
3.Save and execute the flow.
The specified topic is subscribed successfully.
Using mqtt out node¶
To publish the messages using mqtt out node, follow these steps:
-
From the node palette, drag and drop the "inject" node from the input palette and "mqtt out" node from the output palette to the working area. Connect the nodes in a flow as shown below:
-
Double click on "inject" node to edit the properties. For more information, refer to Editing nodes.
-
Double click on "mqtt out" node to edit the properties.
- Enter the "Topic".
- In the output palette, you can select any one of the following options from the dropdown menu.
- Enter the "Name".
-
Click "Done"
-
Save and execute the flow.
The output is displayed in the message payload: