...
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
...
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 . | filePersistenceDirectory | current directory | (Camel 2.16.1 and 2.17) Base directory used by file persistence. Takes no effect if non-file persistence is used. | 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. If there is only a single instance of the MqttConnectOptions in the registry, it will be automatically picked up by the endpoint. |
|
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;
} |
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. Deprecated: from Camel 2.17 onwards the original MqttMessage is not stored as a header but on the org.apache.camel.component.paho.PahoMessage message that has a getter getMqttMessage . | CamelMqttTopic | PahoConstants.MQTT_TOPIC | Consumer | String | Camel 2.17:The topic |
|
Include Page |
---|
| Endpoint See Also |
---|
| Endpoint See Also |
---|
|