Camel Spring Boot

Paho

Send and receive messages to and from MQTT 3.1 and 3.1.1 brokers using the Eclipse Paho MQTT client.

What’s inside

Please refer to the above links for usage and configuration details.

Maven coordinates

<dependency>
    <groupId>org.apache.camel.springboot</groupId>
    <artifactId>camel-paho-starter</artifactId>
</dependency>

Spring Boot Auto-Configuration

The starter supports 33 options, which are listed below.

Name Description Default Type

camel.component.paho.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.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.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.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.clean-session

The MQTT clean session flag. When true, the broker discards the session of the client identifier when the client connects, and the session lasts only as long as the connection; the consumer unsubscribes from the topic when it stops. When false, the broker keeps the subscriptions of the client identifier and queues the QoS 1 and QoS 2 messages for it while the client is offline, and delivers them when a client with the same identifier connects again; this needs a fixed clientId, and the consumer does not unsubscribe when it stops.

true

Boolean

camel.component.paho.client

A shared org.eclipse.paho.client.mqttv3.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.client.mqttv3.MqttClient type.

MqttClient

camel.component.paho.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 number) 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 (cleanSession=false).

String

camel.component.paho.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.PahoConfiguration type.

PahoConfiguration

camel.component.paho.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.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://. The option is a java.util.Properties type.

Properties

camel.component.paho.enabled

Whether to enable auto configuration of the paho component. This is enabled by default.

Boolean

camel.component.paho.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 never shuts down an executor service with it, and the clients that the component creates have no executor service.

1

Integer

camel.component.paho.file-persistence-directory

The base directory of the FILE persistence. The client stores its messages in a subdirectory named after the client identifier and the broker URI. 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.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 client verifies the host name with sslHostnameVerifier if that is set, and otherwise not at all.

true

Boolean

camel.component.paho.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. 0 turns keep alive off. A negative value fails the start.

60

Integer

camel.component.paho.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.manual-acks-enabled

Whether the consumer acknowledges each QoS 1 and QoS 2 message itself when the exchange completes successfully, instead of the Paho client acknowledging it when the message callback returns. When the exchange fails, the message is not acknowledged, and the broker sends it again only when the client reconnects to a session that the broker kept (cleanSession=false). 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.max-inflight

The maximum number of messages that the client publishes at the same time: a QoS 0 message counts until it is written to the network, a QoS 1 or QoS 2 message until the broker acknowledges it. When the limit is reached, publishing a message fails with an MqttException (reason code 32202, too many publishes in progress). Increase it when many threads send to the producer at the same time. 0 makes every publish fail.

10

Integer

camel.component.paho.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). Used only when automaticReconnect is true.

128000

Integer

camel.component.paho.mqtt-version

The MQTT protocol version: 0 connects with MQTT 3.1.1 and falls back to MQTT 3.1 when that connect fails, 4 uses only MQTT 3.1.1 and 3 uses only MQTT 3.1. Any other value fails the start.

Integer

camel.component.paho.password

The password for authentication with the MQTT broker. It is sent only when the userName option is set too.

String

camel.component.paho.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 cleanSession is false (a clean session clears them on connect).

memory

PahoPersistence

camel.component.paho.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 CamelPahoQos header sets another one.

2

Integer

camel.component.paho.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 CamelPahoRetained header overrides this option for a message.

false

Boolean

camel.component.paho.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 cleanSession to false for durable subscriptions), or for independent brokers to try in turn (set cleanSession to true, as their state is not shared).

String

camel.component.paho.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.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.ssl-hostname-verifier

A custom javax.net.ssl.HostnameVerifier for ssl:// and wss:// connections. It is used only when httpsHostnameVerificationEnabled is false: 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. The option is a javax.net.ssl.HostnameVerifier type.

HostnameVerifier

camel.component.paho.user-name

The user name for authentication with the MQTT broker. It is sent only when the password option is set too.

String

camel.component.paho.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.will-qos

The QoS level (0, 1 or 2) with which the broker publishes the will message.

Integer

camel.component.paho.will-retained

Whether the broker publishes the will message as a retained message.

false

Boolean

camel.component.paho.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 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