Since we're on a major migration process of this website, some component documents here are out of sync right now. In the meantime you may want to look at the early version of the new website
https://camel.apache.org/staging/
We would very much like to receive any feedback on the new site, please join the discussion on the Camel user mailing list.
Paho Component
Available as of Camel 2.16 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 formatpaho:queueName[?options] For example the following snippet reads messages from the MQTT broker installed on the same host as the Camel router: from("paho:some/queue"). to("mock:test"); While the snippet below sends message to the MQTT broker: from("direct:test"). to("paho:some/target/queue"); You can append query options to the URI in the following format:
from("paho:some/queue?brokerUrl=tcp://iot.eclipse.org:1883"). to("mock:test");
Adding the component to the projectMaven users will need to add the following dependency to their <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: <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: // 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 transformations for you. In the example below Camel automatically converts binary payload into String (and conversely):
// Receive payload String payload = consumerTemplate.receiveBody("paho:topic", String.class); // Send payload String payload = "message"; producerTemplate.sendBody("paho:topic", payload); URI Options
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 @Bean MqttConnectOptions connectOptions() { MqttConnectOptions connectOptions = new MqttConnectOptions(); connectOptions.setUserName("henry"); connectOptions.setPassword("secret".toCharArray()); return connectOptions; } HeadersThe following headers are recognized by the Paho component:
|