...
Code Block |
---|
paho:queueName[?options] |
For example the following snippet reads messages from the MQTT broker installed on the same host as the Camel router:
Code Block |
---|
from("paho:some/queue").
to("mock:test"); |
While the snippet below sends message to the MQTT broker:
Code Block |
---|
from("direct:test").
to("paho:some/target/queue"); |
You can append query options to the URI in the following format: ?option=value&option=value&...
. For example this is how to read messages from the remote MQTT broker:
Code Block |
---|
from("paho:some/queue?brokerUrl=tcp://iot.eclipse.org:1883").
to("mock:test"); |
Adding the component to the project
...
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); |
...
Div | |||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| |||||||||||||||||||||
|
For example the convention-over-configuration approach used in Camel is really handy for the most of the situations, but sometimes you would like to have more fine-grained control over the MQTT client connection. To cover such situations just add the bean of type org.eclipse.paho.client.mqttv3.MqttConnectOptions
to your Camel registry. For Spring applications that would means adding bean to your application context. The snippet below uses password-based authentication to connect to the MQTT broker:
Code Block |
---|
@Bean MqttConnectOptions connectOptions() { MqttConnectOptions connectOptions = new MqttConnectOptions(); connectOptions.setUserName("henry"); connectOptions.setPassword("secret".toCharArray()); return connectOptions; } |
Headers
The following headers are recognized by the Paho component:
Div | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||
|
Examples
Read messages from the MQTT broker installed on the same host as the Camel router:
Code Block |
---|
from("paho:some/queue").
to("mock:test"); |
Read messages from the remote MQTT broker:
Code Block |
---|
from("paho:some/queue?brokerUrl=tcp://iot.eclipse.org:1883").
to("mock:test"); |
Send message to the MQTT broker:
...
|
Include Page | ||||
---|---|---|---|---|
|