Repository: camel Updated Branches: refs/heads/master 0ced4e92e -> 6fe1ec4b0
Polished docs Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/6fe1ec4b Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/6fe1ec4b Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/6fe1ec4b Branch: refs/heads/master Commit: 6fe1ec4b01106ef562e9c36c1f2042fb9e9a1e0b Parents: 0ced4e9 Author: Claus Ibsen <davscl...@apache.org> Authored: Thu Oct 5 09:46:34 2017 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Thu Oct 5 09:46:34 2017 +0200 ---------------------------------------------------------------------- .../src/main/docs/paho-component.adoc | 165 ++++++++----------- 1 file changed, 72 insertions(+), 93 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/6fe1ec4b/components/camel-paho/src/main/docs/paho-component.adoc ---------------------------------------------------------------------- diff --git a/components/camel-paho/src/main/docs/paho-component.adoc b/components/camel-paho/src/main/docs/paho-component.adoc index 0186bea..e07fef7 100644 --- a/components/camel-paho/src/main/docs/paho-component.adoc +++ b/components/camel-paho/src/main/docs/paho-component.adoc @@ -7,64 +7,24 @@ the https://eclipse.org/paho/[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 - -[source,java] ------------------------- -paho:queueName[?options] ------------------------- - -For example the following snippet reads messages from the MQTT broker -installed on the same host as the Camel router: - -[source,java] ------------------------- -from("paho:some/queue"). - to("mock:test"); ------------------------- - -While the snippet below sends message to the MQTT broker: - -[source,java] -------------------------------- -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: - - - -[source,java] -------------------------------------------------------------- -from("paho:some/queue?brokerUrl=tcp://iot.eclipse.org:1883"). - to("mock:test"); -------------------------------------------------------------- - - - -### Adding the component to the project - Maven users will need to add the following dependency to their `pom.xml` for this component: [source,xml] ------------------------------------------------------------- +---- <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: [source,xml] --------------------------------------------------------------------------- +---- <repositories> <repository> <id>eclipse-paho</id> @@ -74,47 +34,20 @@ you need to add Eclipse Paho repository to your POM xml file: </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: +---- -[source,java] ---------------------------------------------------------------------- -// Receive payload -byte[] payload = (byte[]) consumerTemplate.receiveBody("paho:topic"); - -// Send payload -byte[] payload = "message".getBytes(); -producerTemplate.sendBody("paho:topic", payload); ---------------------------------------------------------------------- - +=== URI format -But of course Camel build-in link:type-converter.html[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): - - - -[source,java] --------------------------------------------------------------------------- -// Receive payload -String payload = consumerTemplate.receiveBody("paho:topic", String.class); - -// Send payload -String payload = "message"; -producerTemplate.sendBody("paho:topic", payload); --------------------------------------------------------------------------- +[source] +---- +paho:topic[?options] +---- -### Paho Options +Where *topic* is the name of the topic. +=== Options // component options: START The Paho component supports 4 options which are listed below. @@ -172,27 +105,73 @@ with the following path and query parameters: // endpoint options: END -### Headers +=== Headers The following headers are recognized by the Paho component: [width="100%",cols="10%,10%,10%,10%,60%",options="header",] -|======================================================================= +|=== |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 |The name of the topic +|=== + + +=== Default payload type + +By default Camel Paho component operates on the binary payloads +extracted out of (or put into) the MQTT message: + +[source,java] +---- +// 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 link:type-converter.html[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): -|`CamelMqttTopic` |PahoConstants.MQTT_TOPIC |Consumer |String |*Camel 2.17:*The topic -|======================================================================= - +[source,java] +---- +// Receive payload +String payload = consumerTemplate.receiveBody("paho:topic", String.class); -### See Also +// Send payload +String payload = "message"; +producerTemplate.sendBody("paho:topic", payload); +---- + + +=== Samples + +For example the following snippet reads messages from the MQTT broker +installed on the same host as the Camel router: + +[source,java] +---- +from("paho:some/queue") + .to("mock:test"); +---- + +While the snippet below sends message to the MQTT broker: + +[source,java] +---- +from("direct:test") + .to("paho:some/target/queue"); +---- + +For example this is how to read messages from the remote MQTT broker: + +[source] +---- +from("paho:some/queue?brokerUrl=tcp://iot.eclipse.org:1883") + .to("mock:test"); +---- -* link:configuring-camel.html[Configuring Camel] -* link:component.html[Component] -* link:endpoint.html[Endpoint] -* link:getting-started.html[Getting Started]