...
Paho component provides connector for the MQTT messaging protocol using the Eclipse Paho library. Paho is one of the most popular MQTT libraries, so if you would like to integrate it with your Java project - Camel Paho connector is a way to go.
URI format
Code Block |
---|
paho:queueName[?options]
|
You can append query options to the URI in the following format: ?option=value&option=value&...
.
Adding the component to the project
...
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 build-in type conversion API can perform the automatic data type conversions transformations for you. In the example below Camel automatically converts binary payload into String (and conversely):
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]
|
...
URI Options
Div | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||||
|
...