MQTT Subscriber
This adapter allows to subscribe to a topic in an MQTT broker.
The MQTT protocol provides a simple method for sending messages via a publish/subscribe model. This makes it particularly suitable for messaging in the internet of things environment, such as low-power sensors or mobile devices like telephones, embedded computers or micro-controllers.
Note:
The MQTT Subscriber is mostly used in combination with the MQTT Publisher.
Properties
Operation | Defines the operation executed by the adapter. Possible values:
|
Parameters
Adapter | Adapter main class (do not change!) Possible values: de.softproject.integration.adapter. mqtt.MqttSubscriberAdapter: Main class (default) |
Alias | Broker alias Possible values:
The alias can be defined within the configuration file |
ClientId | Identifier for the client that subscribes to the broker. Possible values:
The Client ID can be defined within the configuration file |
clientTimeout | Timeout for ONLINE_ON_DEMAND connections (for the operation Possible values: Integer greater than |
connectionMode | Connection mode selected to create the Client. Depending on the selected value, the client connection is held or disconnected after a certain time ( Possible values:
This parameter is not required if |
stateful | Defines if the state between client and broker is stateful. Possible values: This parameter is not required if |
keystorePath | Path to the keystore. If no SSL/TLS configuration is required to connect to the broker, this parameter value may be empty. Possible values: File system path This parameter is not required if |
keystorePassword | Password for the keystore specified for Possible values: Any string This parameter is not required if |
Topic | Name of the topic that the client subscribes to. Possible values: Any string The topic can be defined within the configuration file |
server | Protocol, host and port to connect client and broker. Possible values:
This parameter is not required if |
InputFormat | Input format of the adapter Possible values:
|
loginUsername | Username that is used to connect to a broker that requires credentials. Possible values: Username This parameter is not required if |
loginPassword | Password that is used to connect to a broker that requires credentials. Possible values: Password This parameter is not required if |
QoS | Quality of Service, for receiving messages when subscribing to a topic. Possible values:
This parameter is not required if |
process | Path to the process that is executed each time a message of the subscribed topic is received. Possible values: Process path in the format |
Status values
1 | The adapter operation was executed successfully. |
-1 | An error occurred during connection establishment, disconnection, publishing or subscription. |
Input
The adapter expects no input document.
Output
The output is the same as the input.
Configuration file
To define broker, client, SSL/TLS configurations etc. a configuration file with a specified structure can be used, which is loaded at server startup. The configuration file mqttconfig.xml
must be stored under the server path X4DB/0
. If broker and client are defined in the configuration file, then only the values for alias
and cliendId
have to be specified in the adapter parameters.
The file contains the following information:
KeyStore | Path and password of the keystore that is used to establish a SSL connection to a broker. If this optional element is not defined, a trust manager is created that accepts all certificates. When specifying the path, both absolute and relative paths to Example: Relative path specification
XML
Absolute path specification
XML
|
---|---|
Broker | MQTT server Relevant information is embedded in the attribute
|
Topic | Topic that can be subscribed to to receive the published message. It has the following attributes:
|
Sample configuration
<?xml version='1.0' encoding='UTF-8'?>
<RootElement>
<!-- Both, relative and absolute paths to X4DB/0 are allowed -->
<KeyStore password="password">C:/Users/MaxMustermann/Documents/MQTT/Keystore/application.keystore</KeyStore>
<Broker alias="Mosquitto_MQTT">
<Server>ssl://localhost:8883</Server>
<ClientId mode="ALWAYS_ONLINE_ON_STARTUP">C1</ClientId>
<ClientId mode="ALWAYS_ONLINE_ON_FIRST_PUBLISH">C2</ClientId>
<ClientId timeout="40" mode="ONLINE_ON_DEMAND">C3</ClientId>
<ClientId timeout="20" mode="ONLINE_ON_DEMAND">C4</ClientId>
<Topic filter="topic/action1" qos="AT_LEAST_ONCE">
<Process url="x4db://1/X4Experience/ESB/3-Reference/1-AdapterSuites/X4MQTTAdapter/Processes/TopicProcesses/ProcessTopic1.wrf"/>
</Topic>
<Topic filter="topic/action2" qos="AT_MOST_ONCE">
<Process url="x4db://1/X4Experience/ESB/3-Reference/1-AdapterSuites/X4MQTTAdapter/Processes/TopicProcesses/ProcessTopic2.wrf"/>
</Topic>
<Topic filter="topic/action1" qos="EXACTLY_ONCE">
<Process url="x4db://1/X4Experience/ESB/3-Reference/1-AdapterSuites/X4MQTTAdapter/Processes/TopicProcesses/ProcessTopic3.wrf"/>
</Topic>
</Broker>
</RootElement>