camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > MQTT
Date Fri, 08 Jun 2012 14:10:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/CAMEL/MQTT">MQTT</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~rajdavies">Rob
Davies</a>
    </h4>
        <br/>
                         <h4>Changes (1)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >{div:class=confluenceTableSmall} <br>||
Property || Default || Description || <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">|
{{host}} | {{tcp://127.0.0.1:1883}} | The URI of the MQTT broker to connect too - this component
also supports SSL - e.g. _ssl://127.0.0.1:8883_| <br>| {{localAddress}} | | The local
InetAddress and port to use | <br>| {{connectAttemptsMax}} | {{-1}} | The maximum number
of attempts to establish an initial connection - *_-1_* in infinite. | <br>| {{reconnectAttemptsMax}}
| {{-1}} | The maximum number of attempts to re-establish a connection after failure - *_-1_*
in infinite. | <br>| {{reconnectDelay}} | {{10}} | The time in milliseconds between
attempts to reestablish an initial or failed connection | <br>| {{reconnectBackOffMultiplier}}
| {{2.0}} | The multiplier to use to the delay between connection attempts for successive
failed connection attempts | <br>| {{reconnectDelayMax}} | {{30000}} | The maximum time
in milliseconds between a new attempt to establish a connection. So even using the reconnectBackOffMultiplier,
this property will define the maximum delay before another connection attempt to the MQTT
broker  | <br></td></tr>
            <tr><td class="diff-unchanged" >| {{QoS}} | {{AtLeastOnce}} | The
MQTT Quality of Service to use for message exchanges. It can be one of *AtMostOnce*, *AtLeastOnce*
or *ExactlyOnce* | <br>| {{subscribeTopicName}} | |  The name of the Topic to subscribe
to for messages | <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="MQTT-MQTTComponent"></a>MQTT Component</h2>

<p>The <b>mqtt:</b> component is used for communicating with <a href="http://mqtt.org"
class="external-link" rel="nofollow">MQTT</a> compliant message brokers, like Apache
ActiveMQ or Mosquitto</p>

<p>Camel will poll the feed every 60 seconds by default.<br/>
<b>Note:</b> The component currently only supports polling (consuming) feeds.</p>

<p>Maven users will need to add the following dependency to their <tt>pom.xml</tt>
for this component:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;dependency&gt;</span>
    <span class="code-tag">&lt;groupId&gt;</span>org.apache.camel<span
class="code-tag">&lt;/groupId&gt;</span>
    <span class="code-tag">&lt;artifactId&gt;</span>camel-mqtt<span
class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>x.x.x<span class="code-tag">&lt;/version&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- use the same
version as your Camel core version --&gt;</span></span>
<span class="code-tag">&lt;/dependency&gt;</span>
</pre>
</div></div>

<h3><a name="MQTT-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
mqtt:<span class="code-comment">//name[?options]</span>
</pre>
</div></div>

<p>Where <b>name</b> is the name you want to assign the component.</p>

<h3><a name="MQTT-Options"></a>Options</h3>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Property </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>host</tt> </td>
<td class='confluenceTd'> <tt>tcp://127.0.0.1:1883</tt> </td>
<td class='confluenceTd'> The URI of the MQTT broker to connect too - this component
also supports SSL - e.g. <em>ssl://127.0.0.1:8883</em></td>
</tr>
<tr>
<td class='confluenceTd'> <tt>localAddress</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> The local InetAddress and port to use </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>connectAttemptsMax</tt> </td>
<td class='confluenceTd'> <tt>-1</tt> </td>
<td class='confluenceTd'> The maximum number of attempts to establish an initial connection
- <b><em>-1</em></b> in infinite. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>reconnectAttemptsMax</tt> </td>
<td class='confluenceTd'> <tt>-1</tt> </td>
<td class='confluenceTd'> The maximum number of attempts to re-establish a connection
after failure - <b><em>-1</em></b> in infinite. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>reconnectDelay</tt> </td>
<td class='confluenceTd'> <tt>10</tt> </td>
<td class='confluenceTd'> The time in milliseconds between attempts to reestablish an
initial or failed connection </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>reconnectBackOffMultiplier</tt> </td>
<td class='confluenceTd'> <tt>2.0</tt> </td>
<td class='confluenceTd'> The multiplier to use to the delay between connection attempts
for successive failed connection attempts </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>reconnectDelayMax</tt> </td>
<td class='confluenceTd'> <tt>30000</tt> </td>
<td class='confluenceTd'> The maximum time in milliseconds between a new attempt to
establish a connection. So even using the reconnectBackOffMultiplier, this property will define
the maximum delay before another connection attempt to the MQTT broker  </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>QoS</tt> </td>
<td class='confluenceTd'> <tt>AtLeastOnce</tt> </td>
<td class='confluenceTd'> The MQTT Quality of Service to use for message exchanges.
It can be one of <b>AtMostOnce</b>, <b>AtLeastOnce</b> or <b>ExactlyOnce</b>
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>subscribeTopicName</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'>  The name of the Topic to subscribe to for messages </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>publishTopicName</tt> </td>
<td class='confluenceTd'> <tt><em>camel/mqtt/test</em></tt>
</td>
<td class='confluenceTd'> The default Topic to publish messages on </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>byDefaultRetain</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> The default retain policy to be used on messages sent to the
MQTT broker</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>mqttTopicPropertyName</tt> </td>
<td class='confluenceTd'> <tt>_MQTTTopicPropertyName+</tt> </td>
<td class='confluenceTd'> The property name to look for on an Exchange for an individual
published message. If this is set - the name will be used as the Topic to publish a message
to the MQTT message broker. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>mqttRetainPropertyName</tt> </td>
<td class='confluenceTd'> <tt>MQTTRetain</tt> </td>
<td class='confluenceTd'> The property name to look for on an Exchange for an individual
published message. If this is set (expects a Boolean value) - then the retain property will
be set on the message sent to the MQTT message broker. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>mqttQosPropertyName</tt> </td>
<td class='confluenceTd'> <tt>MQTTQos</tt> </td>
<td class='confluenceTd'> The property name to look for on an Exchange for an individual
published message. If this is set (one of <b>AtMostOnce</b>, <b>AtLeastOnce</b>
or <b>ExactlyOnce</b>  ) - then that QoS will be set on the message sent to the
MQTT message broker. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>connectWaitInSeconds</tt> </td>
<td class='confluenceTd'> <tt>10</tt> </td>
<td class='confluenceTd'> Delay in seconds the Component will wait for a connection
to be established to the MQTT broker </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>disconnectWaitInSeconds</tt> </td>
<td class='confluenceTd'> <tt>5</tt> </td>
<td class='confluenceTd'>the number of seconds the Component will wait for a valid disconnect
on stop() from the MQTT broker </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>sendWaitInSeconds</tt> </td>
<td class='confluenceTd'> <tt>5</tt> </td>
<td class='confluenceTd'> The maximum time the Component will wait for a receipt from
the MQTT broker to acknowledge a published message before throwing an exception</td>
</tr>
</tbody></table>
</div>
</div>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>


<h3><a name="MQTT-Samples"></a>Samples</h3>

<p>Sending messages:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:foo"</span>).to(<span class="code-quote">"mqtt:cheese?publishTopicName=test.mqtt.topic"</span>);
</pre>
</div></div>

<p>Consuming messages:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"mqtt:bar?subscribeTopicName=test.mqtt.topic"</span>).transform(body().convertToString()).to(<span
class="code-quote">"mock:result"</span>)
</pre>
</div></div>


<h2><a name="MQTT-Endpoints"></a>Endpoints</h2>

<p>Camel supports the <a href="/confluence/display/CAMEL/Message+Endpoint" title="Message
Endpoint">Message Endpoint</a> pattern using the <a href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/Endpoint.html"
class="external-link" rel="nofollow">Endpoint</a> interface. Endpoints are usually
created by a <a href="/confluence/display/CAMEL/Component" title="Component">Component</a>
and Endpoints are usually referred to in the <a href="/confluence/display/CAMEL/DSL" title="DSL">DSL</a>
via their <a href="/confluence/display/CAMEL/URIs" title="URIs">URIs</a>. </p>

<p>From an Endpoint you can use the following methods</p>
<ul>
	<li><a href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/Endpoint.html#createProducer()"
class="external-link" rel="nofollow">createProducer()</a> will create a <a href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/Producer.html"
class="external-link" rel="nofollow">Producer</a> for sending message exchanges to
the endpoint</li>
	<li><a href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/Endpoint.html#createConsumer(org.apache.camel.Processor)"
class="external-link" rel="nofollow">createConsumer()</a> implements the <a href="/confluence/display/CAMEL/Event+Driven+Consumer"
title="Event Driven Consumer">Event Driven Consumer</a> pattern for consuming message
exchanges from the endpoint via a <a href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/Processor.html"
class="external-link" rel="nofollow">Processor</a> when creating a <a href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/Consumer.html"
class="external-link" rel="nofollow">Consumer</a></li>
	<li><a href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/Endpoint.html#createPollingConsumer()"
class="external-link" rel="nofollow">createPollingConsumer()</a> implements the <a
href="/confluence/display/CAMEL/Polling+Consumer" title="Polling Consumer">Polling Consumer</a>
pattern for consuming message exchanges from the endpoint via a <a href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/PollingConsumer.html"
class="external-link" rel="nofollow">PollingConsumer</a></li>
</ul>



<h3><a name="MQTT-SeeAlso"></a>See Also</h3>

<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring
Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Message+Endpoint" title="Message Endpoint">Message
Endpoint</a> pattern</li>
	<li><a href="/confluence/display/CAMEL/URIs" title="URIs">URIs</a></li>
	<li><a href="/confluence/display/CAMEL/Writing+Components" title="Writing Components">Writing
Components</a></li>
</ul>

    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/MQTT">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=27849019&revisedVersion=2&originalVersion=1">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/MQTT?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message