camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > ZeroMQ
Date Sat, 29 Dec 2012 09:41: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/ZeroMQ">ZeroMQ</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~davsclaus">Claus
Ibsen</a>
    </h4>
        <br/>
                         <h4>Changes (2)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-unchanged" >h2. Camel ZeroMQ Component <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">*Available
as of Camel 2.10* <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">*Not
Yet Available* <br> <br></td></tr>
            <tr><td class="diff-unchanged" >The *zeromq:* component allows you
to consumer or produce messages using [ZeroMQ|http://zeromq.org/]. Zeromq requires a bit of
work to get setup, especially on windows. Refer to [the documentation|http://www.zeromq.org/intro:get-the-software].
Note: This component works with the stable 2.2 branch and not the pre-release 3.2. <br>
<br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="ZeroMQ-CamelZeroMQComponent"></a>Camel ZeroMQ Component</h2>
<p><b>Available as of Camel 2.10</b></p>

<p>The <b>zeromq:</b> component allows you to consumer or produce messages
using <a href="http://zeromq.org/" class="external-link" rel="nofollow">ZeroMQ</a>.
Zeromq requires a bit of work to get setup, especially on windows. Refer to <a href="http://www.zeromq.org/intro:get-the-software"
class="external-link" rel="nofollow">the documentation</a>. Note: This component
works with the stable 2.2 branch and not the pre-release 3.2.</p>

<p>This component uses Akka for it's Zeromq "driver" but does not use Scala Actors.
This means the component does not require the JZMQ libraries to be built and present, just
the native ZeroMQ library that is installed when you build ZeroMQ on your system. There is
some discussion as to the speed of the Akka driver, and so it is possible to switch to using
the JZMQ driver if you wish. Simply remove the Akka Zeromq dependancy and replace it with
the JZMQ jar and ensure the zmq.lib is present on your system. For more information see <a
href="http://www.zeromq.org/bindings:java" class="external-link" rel="nofollow">here</a>.</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-zeromq<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="ZeroMQ-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
zeromq:(tcp|ipc):<span class="code-comment">//hostname:port[?options...]</span>
</pre>
</div></div>

<p>Where <b>hostname</b> is the hostname or ip where the server will run.
</p>

<h3><a name="ZeroMQ-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>socketType</tt> </td>
<td class='confluenceTd'> <tt>none</tt> </td>
<td class='confluenceTd'> Choose from PULL, SUBSCRIBE for consumers, or PUSH, PUBLISH
for producers </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>asyncConsumer</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Sets the consumer to be async. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>topics</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Applicable for subscribers and publishers only. Determines
which topics to subscribe or publish to. If not specified then the subscriber will subscribe
to all messages. If not specified by a publisher then no topic will be prefixed to the message.
Specify multiple topics by a comma separated list </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>messageIdEnabled</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> If enabled then camel-zeromq will add a unique UUID to each
message as it is received </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>messageConvertor</tt> </td>
<td class='confluenceTd'> <tt>DefaultMessageConvertor</tt> </td>
<td class='confluenceTd'> The message convertor that is used to turn an exchange into
a byte array for dispatch through zeromq. See later section. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>highWaterMark</tt> </td>
<td class='confluenceTd'> <tt>-1</tt> </td>
<td class='confluenceTd'> By default, zeromq will keep messages in an in-memory buffer
while waiting for clients to receive. The high water mark is the max number of messages to
hold before throwing an exception. -1 sets to the zeromq default, 0 disables, and any positive
value sets to that value. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>linger</tt> </td>
<td class='confluenceTd'> <tt>-1</tt> </td>
<td class='confluenceTd'> By default, zeromq will wait for sending messages to be received
before shutting down. Linger is the number of seconds to wait before force closing the socket.
-1 sets to the zeromq default, 0 disables, and any positive value sets to that value. </td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="ZeroMQ-Headers"></a>Headers</h3>

<p>The follwing headers are set on exchanges during message transport.</p>

<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Header Name </th>
<th class='confluenceTh'> Endpoint Type </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> ZeroMQMessageId </td>
<td class='confluenceTd'> Consumer </td>
<td class='confluenceTd'> A type 4 UUID that is added to received messages </td>
</tr>
<tr>
<td class='confluenceTd'> ZeroMQTimestamp </td>
<td class='confluenceTd'> Both </td>
<td class='confluenceTd'> The timestamp when the message was received </td>
</tr>
<tr>
<td class='confluenceTd'> ZeroMQSource </td>
<td class='confluenceTd'> Both </td>
<td class='confluenceTd'> The socket address where the message was received from or
pushed to </td>
</tr>
<tr>
<td class='confluenceTd'> ZeroMQSocketType </td>
<td class='confluenceTd'> Both </td>
<td class='confluenceTd'> The type of zeromq that the message was received from or pushed
to </td>
</tr>
</tbody></table>
</div>


<h3><a name="ZeroMQ-MessageConversion"></a>Message Conversion</h3>

<p>ZeroMQ sends its messages as a byte stream and so incoming messages have the body
set as a byte[] array. When sending to a producer, the messageConvertor is invoked, and passed
the Exchange. The DefaultMessageConvertor will return the body as is, if it is a byte array,
otherwise it will call toString().getBytes(). You can provide custom conversion strategies
by specifying a class to the messageConvertor option on the endpoint.</p>

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

<p>To receive all messages from a publisher, and then print those to a logger:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"zeromq:tcp:<span class="code-comment">//127.0.0.1:5555"</span>).process(someLoggingProcessor);</span>
</pre>
</div></div>

<p>To broadcast a message every second on three topics:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
        from(<span class="code-quote">"timer:<span class="code-comment">//foo?fixedRate=<span
class="code-keyword">true</span>&amp;period=10"</span>).process(<span
class="code-keyword">new</span> Processor() {
</span>        
        List&lt;<span class="code-object">String</span>&gt; asList = Arrays.asList(<span
class="code-quote">"coldplay"</span>, <span class="code-quote">"keane"</span>,
<span class="code-quote">"jethro tull"</span>, <span class="code-quote">"jack
bruce"</span>, <span class="code-quote">"elton john"</span>, <span class="code-quote">"kate
bush"</span>);

			@Override
			<span class="code-keyword">public</span> void process(Exchange exchange) <span
class="code-keyword">throws</span> Exception {
				Collections.shuffle(asList);
				exchange.getIn().setBody(asList.get(0));
			}
		}).to(<span class="code-quote">"zeromq:tcp:<span class="code-comment">//127.0.0.1:5556?socketType=PUBLISH&amp;topics=bands,musicians,singers"</span>);</span>
</pre>
</div></div>
    </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/ZeroMQ">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=30149633&revisedVersion=2&originalVersion=1">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/ZeroMQ?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message