...
Code Block |
---|
|
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-paho</artifactId>
<version>x.y.z</version>
<!-- use the same version as your Camel core version -->
</dependency>
|
Keep in mind that Paho artifacts are not hosted in the Maven Central, so you need to add Eclipse Paho repository to your POM xml file:
Code Block |
---|
|
<repositories>
<repository>
<id>eclipse-paho</id>
<url>https://repo.eclipse.org/content/repositories/paho-releases</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories> |
Default payload type
By default Camel Paho component operates on the binary payloads extracted out of or put into the MQTT message:
Code Block |
---|
// Receive payload
byte[] payload = (byte[]) consumerTemplate.receiveBody("paho:topic");
// Send payload
byte[] payload = "message".getBytes();
producerTemplate.sendBody("paho:topic", payload); |
But of course Camel can perform the automatic data type conversions for you:
Code Block |
---|
// Receive payload
String payload = consumerTemplate.receiveBody("paho:topic", String.class);
// Send payload
String payload = "message";
producerTemplate.sendBody("paho:topic", payload); |
URI format
Code Block |
---|
paho:queueName[?options]
|
...
Div |
---|
class | confluenceTableSmall |
---|
|
Option | Default | Description |
---|
clientId | camel-<timestamp> | MQTT client identifier. | brokerUrl
| tcp://localhost:1883
| The URL of the MQTT broker. | persistence | memory | Client persistence to be used - memory or file . | qos | 2 | Client quality of service level (0 -2 ). | connectOptions | none | The reference to the org.eclipse.paho.client.mqttv3.MqttConnectOptions instance located in the Camel registry. Referenced MqttConnectOptions instance will be used by the endpoint to initialize the connection. For example connectOptions=#my ConnectOptions notation can be used to reference Spring bean named my ConnectOptions. |
|
The following headers are recognized by the Paho component:
Div |
---|
class | confluenceTableSmall |
---|
|
Header | Java constant | Endpoint type | Value type | Description |
---|
PahoOriginalMessage | PahoConstants.HEADER_ORIGINAL_MESSAGE | Consumer | org.eclipse.paho.client.mqttv3.MqttMessage | The original Paho message instance received by the client. |
|
Examples
Read messages from the MQTT broker installed on the same host as the Camel router:
...