MQTT 5 Source
Provided by: "Apache Software Foundation"
Support Level for this Kamelet is: "Stable"
Receives each message published to a topic on an MQTT broker, such as Eclipse Mosquitto or HiveMQ, with MQTT 5.
Use it to collect readings and events from IoT devices and other MQTT clients, when the broker or the clients use MQTT 5. A topic with wildcards, such as sensors/#, receives from many topics at once. For a broker that only speaks MQTT 3.1.1, use mqtt-source.
Output: the body is the payload, as bytes. The CamelMqttTopic header is the topic the message was published to, CamelMqttQoS its quality of service, and CamelPahoMqtt5MsgProperties holds the MQTT 5 properties of the message, such as its user properties.
Good to know: it receives only the messages published while it is connected, plus, when it subscribes, the last retained message of each matching topic. It subscribes with quality of service 2 (exactly once) unless qos is set. Each running copy needs its own clientId: two clients with the same ID keep pushing each other off the broker and lose messages. When it is not set, a unique one is generated. It connects with no TLS unless brokerUrl starts with ssl://. With TLS it checks the certificate and the host name of the broker, and trusts the certificate authorities that Java trusts by default, or instead the ones in sslTruststoreLocation. The integration fails to start when the broker cannot be reached or fails these checks.
Configuration Options
The following table summarizes the configuration options available for the mqtt5-source Kamelet:
| Property | Name | Description | Type | Default | Example |
|---|---|---|---|---|---|
Broker URL | Required The address of the MQTT broker, as | string | tcp://mosquitto:1883 | ||
Topic | Required The topic to subscribe to. | string | sensors/# | ||
Client ID | The client ID that names this connection to the broker. It must be unique on the broker: a second client with the same ID pushes the first one off. When it is not set, a unique ID is generated. | string | sensor-reader-1 | ||
Password | The password to log in to the broker with, for the user | string | |||
Quality of Service | The highest quality of service to receive messages with: 0 (at most once, with no confirmation), 1 (at least once, a message can arrive twice) or 2 (exactly once). The broker sends each message with the lower of this and the quality of service it was published with, which the Enum values: * 0 * 1 * 2 | integer | 1 | ||
SSL Truststore Location | The path of a trust store file, in JKS or PKCS12 format, with the certificate of the authority that signed the certificate of the broker. Needed only with an | string | /etc/mqtt/truststore.jks | ||
SSL Truststore Password | The password of the trust store file in | string | |||
Username | The user name to log in to the broker with. Leave it empty for a broker that accepts clients without a login. | string |
Dependencies
At runtime, the mqtt5-source Kamelet relies upon the presence of the following dependencies:
-
camel:paho-mqtt5
-
camel:kamelet
Camel JBang usage
Prerequisites
-
You’ve installed JBang.
-
You have executed the following command:
jbang app install camel@apache/camel Supposing you have a file named route.yaml with this content:
- route:
from:
uri: "kamelet:mqtt5-source"
parameters:
.
.
.
steps:
- to:
uri: "kamelet:log-sink" You can now run it directly through the following command
camel run route.yaml MQTT 5 Source Kamelet Description
Authentication
The Kamelet logs in to the broker with username and password, or without a login when they are not set. For TLS, use an ssl:// address in brokerUrl. The Kamelet then checks the certificate and the host name of the broker, and trusts the certificate authorities that Java trusts by default. When the broker has a certificate from a private or self-signed authority, put the certificate of that authority in a trust store file (JKS or PKCS12) and set sslTruststoreLocation and sslTruststorePassword; the Kamelet then trusts the authorities in that file instead.
Output format
The body is the MQTT payload, as bytes; it is not turned into JSON. The CamelMqttTopic header is the topic of the message, CamelMqttQoS its quality of service, and CamelPahoMqtt5MsgProperties its MQTT 5 properties.
Configuration
-
topic: the topic to subscribe to, with the+and#wildcards -
brokerUrl: the address of the broker, such astcp://mosquitto:1883 -
clientId: the client ID; a unique one is generated when it is not set -
usernameandpassword: the login, when the broker needs one -
qos: the highest quality of service to receive messages with, 0, 1 or 2; 2 when it is not set. A message is received with the lower of this and the quality of service it was published with, whichCamelMqttQoStells -
sslTruststoreLocationandsslTruststorePassword: the trust store with the certificate authority of the broker, for anssl://broker with a certificate from a private or self-signed authority
The Kamelet receives only the messages published while it is connected, plus, when it subscribes, the last retained message of each matching topic.