MQTT Sub¶
The MQTT Sub node establishes an MQTT client that subscribes to a third-party MQTT server.
Node Type¶
Input.
Input and Output Ability¶
This node does not have an entry point and has 1 exit point. The output can be any format and is the message this client retrieves from the subscribed server.
The subscribed topic is stored in the metadata of the output msg, which can be retrieved using the expression ${metadata.topic}
.
Node Properties¶
Provide MQTT Details
From Server Configurations
Name
The name for this node.
Configuration Method
The method to configure the MQTT server. Configuration methods include the below.
Provide MQTT Details: Configure from scratch. If selected, the following fields are required.
Host: The URL of the MQTT server.
Port: The port of the MQTT server.
Authentication Method: The method by which the request made by this node is authenticated. Values include the below.
Anonymous: Does not need any authentication.
Username/Password: Pass the username/password in the request for authentication. If selected, the following fields are required.
User Name: The user name the client uses to log in to the server.
Password: The password the client uses to log in to the server.
Uni-directional: Use encrypted communication where the MQTT client authenticates the credential obtained from the server. If selected, the following is required.
Certificate: The certificate from the server that the MQTT authenticates.
Bi-directional: Use encrypcted communication where the MQTT client and server both authenticate each other’s credentials. If selected, the following is required.
Certificate: The certificate from the server that the MQTT authenticates.
Client Certificate: The client certificate to be authenticated by the MQTT server.
Client Certificate Key: The client certificate key to be authenticated.
Client Password: The client password to be authenticated.
From Server Configurations: Select a pre-configured MQTT server from the drop-down. For more information, see Server Configurations.
Topic
The topic to subscribe to. You can specify up to 5 topics.
QoS
The highest QoS (Quality of Service) level that can be used to subscribe messages from the MQTT server. The table below shows the 3 QoS levels from low to high (0 to 2). Select a level as per required. The default value is 2.
QoS |
0 |
1 |
2 |
---|---|---|---|
Server (Producer) |
Only 1 message will be sent. It will not be stored nor acknowledged. |
At least 1 message will be sent and acknowledged. The server will resend the message if it does not receive any acknowledgement. |
Only 1 message will be sent, stored, and acknowledged twice. The server will delete the message from the queue after the second acknowledgement. |
Client (Consumer) |
Only 1 message will be received, or not at all. No acknowledgement will be returned. |
At least 1 message will be received. The client will return 2 acknowledgements when it receives the message. |
Only 1 message will be received. The client will return an acknowledgement when it receives the message. The transmission will be completed after the second acknowledgement. |
Advantage |
Fastest and uses the least resources. |
The performance is the best and the message will not be lost. |
Guarantees that each message is received only once and will not be lost. |
Disadvantage |
The message may be lost. |
The client may receive the same message multiple times. |
Slowest and uses the most resources. |
Recommended Scenarios |
|
|
|
Concurrency
The number of messages from MQTT server to be processed at the same time. Setting this can improve processing speed but may disrupt the message order. Therefore, it is recommended to use this when there is a need for optimal performance, but not for the ordering of messages. The range is 1-4, and the default value is 1.
Concurrency depends on the Single Instance Resource of the flow. For more information on single instance resource, see Allocating Runtime Resource. The recommended numbers for single instance resource and concurrency are as follows.
When 1 ≤ single instance resource ≤ 2, concurrency is 1.
When 2 < single instance resource ≤ 4, concurrency is 2.
When 4 < single instance resource ≤ 6, concurrency is 3.
When 6 < single instance resource ≤ 8, concurrency is 4.
Clear Previous Sessions
Clear the previous sessions between the client and server whenever the client reconnects to the server.
Description
The description for this node.
Test Connection
You can click the Test Connection button to test the MQTT connectivity.
Limitations¶
Number of connections: 1
Maximum number of topics: 5
Range of concurrency: 1-4
As the MQTT server is not managed by EnOS, connection problems could occur due to server downtime or other instances that are not within our control.
Samples¶
Input Sample¶
Example of a JSON object as input:
{
"externalId": "externalId",
"timestamp": 24214324324,
"measurepoints": {
"speed": 32,
"heat": 40
}
}
Output Sample¶
Example of a JSON object retrieved from the MQTT server. Its topic information is stored in the metadata.
{
"MetaData":{
"CamelMqttTopic": "officeTemp",
"topic": "officeTemp",
"CamelMqttQoS": "2"
},
"Body":{
"externalId": "externalId",
"timestamp": 24214324324,
"measurepoints": {
"speed": 32,
"heat": 40
}
}
}