Paho MQTT 5
Send and receive messages to and from MQTT 5 brokers using the Eclipse Paho MQTT v5 client.
What’s inside
-
Paho MQTT 5 component, URI syntax:
paho-mqtt5:topic
Please refer to the above links for usage and configuration details.
Maven coordinates
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-paho-mqtt5-starter</artifactId>
</dependency> Spring Boot Auto-Configuration
The starter supports 34 options, which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
camel.component.paho-mqtt5.automatic-reconnect | Whether the client reconnects to the broker by itself when the connection is lost. It waits 1 second before the first attempt, and the wait doubles after each failed attempt while it is below maxReconnectDelay. After a reconnect the consumer subscribes to its topic again. A failure of the first connect, when the consumer or producer starts, is not retried. | true | Boolean |
camel.component.paho-mqtt5.autowired-enabled | Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | Boolean |
camel.component.paho-mqtt5.bridge-error-handler | Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | Boolean |
camel.component.paho-mqtt5.broker-url | The URI of the MQTT broker: tcp:// for MQTT over TCP, ssl:// for MQTT over TLS, ws:// for MQTT over WebSocket or wss:// for MQTT over secure WebSocket, for example tcp://localhost:1883. Without a port, the client uses 1883 for tcp://, 8883 for ssl://, 80 for ws:// and 443 for wss://. When serverURIs is set, the client connects to those URIs instead. | tcp://localhost:1883 | String |
camel.component.paho-mqtt5.clean-start | The MQTT 5 Clean Start flag. When true, the broker discards any existing session of the client identifier when the client connects and starts a new one, the client clears its stored in-flight messages, and the consumer unsubscribes from the topic when it stops. When false, the broker resumes the session of the client identifier, if it still has one, with its subscriptions and the QoS 1 and QoS 2 messages queued while the client was offline, and the consumer does not unsubscribe when it stops. How long the broker keeps a session after the connection closes is set by sessionExpiryInterval, and by default the session ends with the connection: a durable subscription needs cleanStart=false, a sessionExpiryInterval greater than 0 and a fixed clientId. | true | Boolean |
camel.component.paho-mqtt5.client | A shared org.eclipse.paho.mqttv5.client.MqttClient, already connected, that the consumers and producers of all endpoints use instead of creating their own clients. Camel does not connect, disconnect or close this client, and does not apply the connection options to it, such as brokerUrl, clientId, persistence, keepAliveInterval, automaticReconnect, the will and the security options. The option is a org.eclipse.paho.mqttv5.client.MqttClient type. | MqttClient | |
camel.component.paho-mqtt5.client-id | The MQTT client identifier that the client sends to the broker when it connects. When it is not set, each consumer and producer generates an identifier (camel-paho- followed by a random UUID) that changes with every start. The broker allows one connection per client identifier and disconnects the older one, so give each consumer and producer its own identifier. A fixed identifier is needed to resume a session that the broker kept (cleanStart=false and a sessionExpiryInterval greater than 0). | String | |
camel.component.paho-mqtt5.configuration | The shared configuration that each endpoint copies its options from. The options of the endpoint URI override the copied values. The option is a org.apache.camel.component.paho.mqtt5.PahoMqtt5Configuration type. | PahoMqtt5Configuration | |
camel.component.paho-mqtt5.connection-timeout | The maximum time in seconds that the client waits to open the network connection to the broker: the TCP connect, and also the TLS handshake for ssl:// and wss://. 0 means no timeout: the client waits until the connection succeeds or fails. A negative value fails the start. | 30 | Integer |
camel.component.paho-mqtt5.custom-web-socket-headers | Extra HTTP headers that the client sends in the WebSocket opening handshake of ws:// and wss:// connections. Not used for tcp:// and ssl://. | String> | |
camel.component.paho-mqtt5.enabled | Whether to enable auto configuration of the paho-mqtt5 component. This is enabled by default. | Boolean | |
camel.component.paho-mqtt5.executor-service-timeout | The time in seconds that the Paho client waits for its executor service to terminate when it shuts down. It has no effect: the Paho client version that this component uses does not read it. | 1 | Integer |
camel.component.paho-mqtt5.file-persistence-directory | The base directory of the FILE persistence. The client stores its messages in a subdirectory named after the client identifier. When not set, the working directory of the JVM (the user.dir system property) is used. Not used with MEMORY persistence. | String | |
camel.component.paho-mqtt5.https-hostname-verification-enabled | Whether the client verifies, in the TLS handshake of ssl:// and wss:// connections, that the certificate of the broker matches the host name of the broker URI, as HTTPS does. When false, the host name is verified only by sslHostnameVerifier, if that is set. | true | Boolean |
camel.component.paho-mqtt5.keep-alive-interval | The MQTT keep alive interval in seconds: the longest time between two control packets that the client sends. When the client has sent nothing else in this time, it sends a PINGREQ, and the broker disconnects a client that it hears nothing from in one and a half times this interval. The broker can return another value (Server Keep Alive) when the client connects, which the client then uses. 0 turns keep alive off. A negative value fails the start. | 60 | Integer |
camel.component.paho-mqtt5.lazy-start-producer | Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | Boolean |
camel.component.paho-mqtt5.manual-acks-enabled | Whether the consumer acknowledges each QoS 1 and QoS 2 message itself when the exchange completes, instead of the Paho client acknowledging it when the message callback returns. The Paho client holds back only the acknowledgement of a QoS 1 message; it completes the QoS 2 flow on its own. When the exchange of a QoS 1 message fails on a session that the broker keeps (cleanStart=false and a sessionExpiryInterval greater than 0), the consumer connects again so that the broker sends the message again (a client set by the client option is not connected again: the message stays unacknowledged until that client connects again). In all other cases the broker would not send it again, so the failed message is acknowledged. With a client set by the client option, the consumer does not switch that client to manual acknowledgements: set that on the client itself. | false | Boolean |
camel.component.paho-mqtt5.max-reconnect-delay | The limit in milliseconds of the wait between two automatic reconnect attempts. The wait starts at 1 second and doubles after each failed attempt while it is below this limit, so it stops growing at the first value that reaches or passes the limit (with the default, at 128 seconds). The consumer also uses it as the limit of the wait before it reconnects after a failed exchange with manualAcksEnabled. | 128000 | Integer |
camel.component.paho-mqtt5.password | The password for authentication with the MQTT broker. It is sent only when the userName option is set too. | String | |
camel.component.paho-mqtt5.persistence | Where the client stores its QoS 1 and QoS 2 messages that are in flight, so that it can complete their delivery after a reconnect. MEMORY keeps them in memory, so they are lost when the client stops. FILE stores them in files below filePersistenceDirectory, so that a client with the same client identifier can complete them after a restart, when cleanStart is false (a clean start clears them on connect). | memory | PahoMqtt5Persistence |
camel.component.paho-mqtt5.qos | The MQTT quality of service (QoS) level: 0 (at most once), 1 (at least once) or 2 (exactly once). The consumer subscribes to the topic with this QoS, which is the highest QoS with which the broker delivers messages to it. The producer publishes messages with this QoS, unless the CamelPahoMqtt5Qos header sets another one. | 2 | Integer |
camel.component.paho-mqtt5.receive-maximum | The MQTT 5 Receive Maximum that the client sends when it connects: the most QoS 1 and QoS 2 messages that the broker sends to the client without having received their acknowledgement. QoS 0 messages are not limited. With manualAcksEnabled, the messages that are still being routed count against this limit. It must be between 1 and 65535, otherwise the start fails. | 65535 | Integer |
camel.component.paho-mqtt5.retained | Whether the producer publishes messages as retained messages: the broker keeps the last retained message of a topic and sends it to each client that subscribes to the topic later. The CamelPahoMqtt5Retained header overrides this option for a message. | false | Boolean |
camel.component.paho-mqtt5.server-u-r-is | A comma-separated list of broker URIs (in the format of brokerUrl, without spaces) that the client connects to instead of brokerUrl. The client tries them in order and connects to the first one that accepts the connection; the connect fails when none does. Use it for brokers that share their session state (high availability; set cleanStart to false for durable subscriptions), or for independent brokers to try in turn (set cleanStart to true, as their state is not shared). | String | |
camel.component.paho-mqtt5.session-expiry-interval | The MQTT 5 Session Expiry Interval in seconds that the client sends when it connects: how long the broker keeps the session (the subscriptions and the queued QoS 1 and QoS 2 messages) after the network connection closes. A negative value, the default, does not send it, and the broker then uses 0. 0 ends the session when the connection closes, and 4294967295 keeps it without expiry. A value above 4294967295 fails the connect. The broker can return a shorter interval. Set cleanStart to false to resume the session when the client connects again. | -1 | Long |
camel.component.paho-mqtt5.socket-factory | A custom javax.net.SocketFactory that the client uses to create its network sockets. For ssl:// and wss:// broker URIs it must be a javax.net.ssl.SSLSocketFactory, and the sslClientProps option is then not used. For tcp:// and ws:// it must not be an SSLSocketFactory. A factory of the wrong type fails the connect. The option is a javax.net.SocketFactory type. | SocketFactory | |
camel.component.paho-mqtt5.ssl-client-props | The TLS settings for ssl:// and wss:// connections, as Paho SSL properties from which the client creates its SSLSocketFactory. Not used when the socketFactory option is set. The keys are com.ibm.ssl.protocol (TLS when not set), com.ibm.ssl.contextProvider, com.ibm.ssl.keyStore, com.ibm.ssl.keyStorePassword, com.ibm.ssl.keyStoreType, com.ibm.ssl.keyStoreProvider, com.ibm.ssl.keyManager, com.ibm.ssl.trustStore, com.ibm.ssl.trustStorePassword, com.ibm.ssl.trustStoreType, com.ibm.ssl.trustStoreProvider, com.ibm.ssl.trustManager, com.ibm.ssl.enabledCipherSuites (a comma-separated list) and com.ibm.ssl.clientAuthentication. Any other key fails the connect. A key store or trust store that is not set falls back to the javax.net.ssl system properties of the JVM. The option is a java.util.Properties type. | Properties | |
camel.component.paho-mqtt5.ssl-hostname-verifier | A custom javax.net.ssl.HostnameVerifier for ssl:// and wss:// connections. After the TLS handshake the client calls it with the host name of the broker URI, and closes the connection with an SSLPeerUnverifiedException when it returns false. It is called also when httpsHostnameVerificationEnabled is true, in addition to that check. The option is a javax.net.ssl.HostnameVerifier type. | HostnameVerifier | |
camel.component.paho-mqtt5.user-name | The user name for authentication with the MQTT broker. | String | |
camel.component.paho-mqtt5.will-mqtt-properties | The MQTT 5 properties of the will message (an org.eclipse.paho.mqttv5.common.packet.MqttProperties), such as the Will Delay Interval, the Message Expiry Interval, the Content Type or user properties. They are not sent to the broker: the component sets them on the will message, while the Paho client sends only the will properties of its connection options, so the broker publishes the will message without them. The option is a org.eclipse.paho.mqttv5.common.packet.MqttProperties type. | MqttProperties | |
camel.component.paho-mqtt5.will-payload | The payload of the will message (Last Will and Testament), as text that is converted to bytes with the default charset of the JVM. The will message is set only when willTopic is set too. | String | |
camel.component.paho-mqtt5.will-qos | The QoS level (0, 1 or 2) with which the broker publishes the will message. | 1 | Integer |
camel.component.paho-mqtt5.will-retained | Whether the broker publishes the will message as a retained message. | false | Boolean |
camel.component.paho-mqtt5.will-topic | The topic of the will message (Last Will and Testament), which the broker publishes when the connection of the client ends without a normal DISCONNECT, for example when the network fails or the keep alive times out. It cannot contain wildcards. The will message is set only when willPayload is set too. | String |