camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Netty
Date Thu, 01 Apr 2010 13:28:00 GMT
<html>
<head>
    <base href="http://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1519/1/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
     <h2><a href="http://cwiki.apache.org/confluence/display/CAMEL/Netty">Netty</a></h2>
     <h4>Page <b>edited</b> by             <a href="http://cwiki.apache.org/confluence/display/~akarpe">Ashwin
Karpe</a>
    </h4>
     
          <br/>
     <div class="notificationGreySide">
         <h2><a name="Netty-NettyComponent"></a>Netty Component</h2>

<p><b>Available as of Camel 2.3</b></p>

<p>The <b>netty</b> component in Camel is a socket communication component,
based on the <br/>
JBoss Netty community offering (available under an Apache 2.0 license). Netty is a <br/>
NIO client server framework which enables quick and easy development of network applications
<br/>
such as protocol servers and clients. Netty greatly simplifies and streamlines network <br/>
programming such as TCP and UDP socket server.</p>

<p>This camel component supports both producer and consumer endpoints.</p>

<p>The netty component has several options and allows fine-grained control of a number
of <br/>
TCP/UDP communication parameters (buffer sizes, keepAlives, tcpNoDelay etc) and facilitates
<br/>
both In-Only and In-Out communication on a Camel route.</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-java">
&lt;dependency&gt;
    &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
    &lt;artifactId&gt;camel-netty&lt;/artifactId&gt;
    &lt;version&gt;x.x.x&lt;/version&gt;
    &lt;!-- use the same version as your Camel core version --&gt;
&lt;/dependency&gt;
</pre>
</div></div>

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

<p>The URI scheme for a netty component is as follows</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
netty:tcp:<span class="code-comment">//localhost:99999[?options]
</span>netty:udp:<span class="code-comment">//remotehost:99999/[?options]</span>
</pre>
</div></div>

<p>This component supports producer and consumer endpoints for both TCP and UDP.</p>

<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="Netty-Options"></a>Options</h3>
<div class="confluenceTableSmall"><table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>keepAlive</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> boolean setting to ensure socket is not closed due to inactivity
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>tcpNoDelay</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> boolean setting to improve TCP protocol performance </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>broadcast</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> boolean setting to choose Multicast over UDP </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>connectTimeoutMillis</tt> </td>
<td class='confluenceTd'> <tt>10 seconds</tt> </td>
<td class='confluenceTd'> time to wait for a socket connection to be available </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>receiveTimeoutMillis</tt> </td>
<td class='confluenceTd'> <tt>10 seconds</tt> </td>
<td class='confluenceTd'> time to wait for a response to be received on a connection
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>reuseAddress</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> boolean setting to facilitate socket multiplexing </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>sync</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> boolean setting to set endpoint as one-way or request-response
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ssl</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> boolean setting to specify whether SSL encryption is applied
to this endpoint </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>sendBufferSize</tt> </td>
<td class='confluenceTd'> <tt>65536 bytes</tt> </td>
<td class='confluenceTd'> the TCP/UDP buffer sizes to be used during outbound communication
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>receiveBufferSize</tt> </td>
<td class='confluenceTd'> <tt>65536 bytes</tt> </td>
<td class='confluenceTd'> tthe TCP/UDP buffer sizes to be used during inbound communication
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>corePoolSize</tt> </td>
<td class='confluenceTd'> <tt>10 threads</tt> </td>
<td class='confluenceTd'> the number of allocated threads at component startup. Defaults
to 10 </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>maxPoolSize</tt> </td>
<td class='confluenceTd'> <tt>100 threads</tt> </td>
<td class='confluenceTd'> the maximum number of threads that may be allocated to this
endpoint. Defaults to 100 </td>
</tr>
</tbody></table></div>

<h3><a name="Netty-RegistrybasedOptions"></a>Registry based Options</h3>

<p>Codec Handlers and SSL Keystores can be set via a JNDI Registry that is associated
with the Camel Context.<br/>
The values that could be passed in, are the following:</p>

<div class="confluenceTableSmall"><table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>passphrase</tt> </td>
<td class='confluenceTd'> password setting to use in order to encrypt/decrypt payloads
sent using SSH </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>keyStoreFile</tt> </td>
<td class='confluenceTd'> Client side certificate keystore to be used for encryption
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>trustStoreFile</tt> </td>
<td class='confluenceTd'> Server side certificate keystore to be used for encryption
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>sslHandler</tt> </td>
<td class='confluenceTd'> Reference to a class that could be used to return an SSL Handler
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>encoder</tt> </td>
<td class='confluenceTd'> A custom Handler class that can be used to perform special
marshalling of outbound payloads. Must override <tt>org.jboss.netty.channel.ChannelDownStreamHandler</tt>.
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>decoder</tt> </td>
<td class='confluenceTd'> A custom Handler class that can be used to perform special
marshalling of inbound payloads. Must override <tt>org.jboss.netty.channel.ChannelUpStreamHandler</tt>.
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>handler</tt> </td>
<td class='confluenceTd'> A custom Handler class that can be used to perform custom
processing of Netty events triggered <br/>
during communication. Must override <tt>org.jboss.netty.channel.SimpleChannelHandler</tt>.
</td>
</tr>
</tbody></table></div>

<h3><a name="Netty-SendingMessagesto%2FfromaNettyendpoint"></a>Sending Messages
to/from a Netty endpoint</h3>

<h4><a name="Netty-NettyProducer"></a>Netty Producer </h4>
<p>In Producer mode, the component provides the ability to send payloads to a socket
endpoint <br/>
using either TCP or UDP protocols (with optional SSL support).</p>

<p>The producer mode supports both one-way and request-response based operations.</p>

<h4><a name="Netty-NettyConsumer"></a>Netty Consumer</h4>
<p>In Consumer mode, the component provides the ability to:</p>
<ul class="alternate" type="square">
	<li>listen on a specified socket using either TCP or UDP protocols (with optional SSL
support),</li>
	<li>receive requests on the socket using text/xml, binary and serialized object based
payloads and</li>
	<li>send them along on a route as message exchanges.</li>
</ul>


<p>The consumer mode supports both one-way and request-response based operations.</p>

<h3><a name="Netty-UsageSamples"></a>Usage Samples</h3>

<h4><a name="Netty-AUDPNettyendpointusingRequestReplyandserializedobjectpayload"></a>A
UDP Netty endpoint using Request-Reply and serialized object payload</h4>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
RouteBuilder builder = <span class="code-keyword">new</span> RouteBuilder() {
  <span class="code-keyword">public</span> void configure() {
    from(<span class="code-quote">"netty:udp:<span class="code-comment">//localhost:5155?sync=<span
class="code-keyword">true</span>"</span>)
</span>      .process(<span class="code-keyword">new</span> Processor()
{
         <span class="code-keyword">public</span> void process(Exchange exchange)
<span class="code-keyword">throws</span> Exception {
           Poetry poetry = (Poetry) exchange.getIn().getBody();
           poetry.setPoet(<span class="code-quote">"Dr. Sarojini Naidu"</span>);
           exchange.getOut().setBody(poetry);
         }
       }
    }
};
</pre>
</div></div>

<h4><a name="Netty-ATCPbasedNettyconsumerendpointusingOnewaycommunication"></a>A
TCP based Netty consumer endpoint using One-way communication</h4>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
RouteBuilder builder = <span class="code-keyword">new</span> RouteBuilder() {
  <span class="code-keyword">public</span> void configure() {
       from(<span class="code-quote">"netty:tcp:<span class="code-comment">//localhost:5150"</span>)
</span>           .to(<span class="code-quote">"mock:result"</span>); 
  }
};
</pre>
</div></div>

<h4><a name="Netty-AnSSL%2FTCPbasedNettyconsumerendpointusingRequestReplycommunication"></a>An
SSL/TCP based Netty consumer endpoint using Request-Reply communication </h4>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
JndiRegistry registry = <span class="code-keyword">new</span> JndiRegistry(createJndiContext());
registry.bind(<span class="code-quote">"password"</span>, <span class="code-quote">"changeit"</span>);
registry.bind(<span class="code-quote">"ksf"</span>, <span class="code-keyword">new</span>
File(<span class="code-quote">"src/test/resources/keystore.jks"</span>));
registry.bind(<span class="code-quote">"tsf"</span>, <span class="code-keyword">new</span>
File(<span class="code-quote">"src/test/resources/keystore.jks"</span>));

context.createRegistry(registry);
context.addRoutes(<span class="code-keyword">new</span> RouteBuilder() {
  <span class="code-keyword">public</span> void configure() {
      <span class="code-object">String</span> netty_ssl_endpoint = 
         <span class="code-quote">"netty:tcp:<span class="code-comment">//localhost:5150sync=<span
class="code-keyword">true</span>&amp;ssl=<span class="code-keyword">true</span>&amp;passphrase=#password"</span>
</span>         + <span class="code-quote">"&amp;keyStoreFile=#ksf&amp;trustStoreFile=#tsf"</span>;
      <span class="code-object">String</span> return_string =
         <span class="code-quote">"When You Go Home, Tell Them Of Us And Say,"</span>
         + <span class="code-quote">"For Your Tomorrow, We Gave Our Today."</span>;
      
      from(netty_ssl_endpoint)
       .process(<span class="code-keyword">new</span> Processor() {
          <span class="code-keyword">public</span> void process(Exchange exchange)
<span class="code-keyword">throws</span> Exception {
            exchange.getOut().setBody(return_string);                           
          }
       }
  }
});
</pre>
</div></div>

<h3><a name="Netty-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/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting
Started</a></li>
</ul>

<ul class="alternate" type="square">
	<li><a href="/confluence/display/CAMEL/MINA" title="MINA">MINA</a></li>
</ul>

     </div>
     <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href="http://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
       </div>

       <a href="http://cwiki.apache.org/confluence/display/CAMEL/Netty">View Online</a>
       |
       <a href="http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=14814487&revisedVersion=19&originalVersion=18">View
Change</a>
              |
       <a href="http://cwiki.apache.org/confluence/display/CAMEL/Netty?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message