camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Fine Grained Control Over a Channel
Date Tue, 26 Jan 2010 10:13: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/Fine+Grained+Control+Over+a+Channel">Fine
Grained Control Over a Channel</a></h2>
     <h4>Page <b>edited</b> by             <a href="http://cwiki.apache.org/confluence/display/~huntc">Christopher
Hunt</a>
    </h4>
     
          <br/>
     <div class="notificationGreySide">
         <h1><a name="FineGrainedControlOveraChannel-Introduction"></a>Introduction</h1>
<p>When sending an <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a>
to an <a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a>
you can either use a <a href="/confluence/display/CAMEL/Routes" title="Routes">Route</a>
or a <a href="/confluence/display/CAMEL/ProducerTemplate" title="ProducerTemplate">ProducerTemplate</a>.
This works fine in many scenarios. However you may need to guarantee that an exchange is delivered
to the same endpoint that you delivered a previous exchange on. For example in the case of
delivering a batch of exchanges to a <a href="/confluence/display/CAMEL/MINA" title="MINA">MINA</a>
socket you may need to ensure that they are all delivered through the same socket connection.
Furthermore once the batch of exchanges have been delivered the protocol requirements may
be such that you are responsible for closing the socket.</p>

<h1><a name="FineGrainedControlOveraChannel-UsingaProducer"></a>Using a
Producer</h1>
<p>To achieve fine grained control over sending exchanges you will need to program directly
to a Producer. Your code will look similar to:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
  CamelContext camelContext = ...

  <span class="code-comment">// Obtain an endpoint and create the producer we will be
using.
</span>  Endpoint endpoint = camelContext.getEndpoint(<span class="code-quote">"someuri:etc"</span>);
  Producer producer = endpoint.createProducer();
  producer.start();

  <span class="code-keyword">try</span> {
    <span class="code-comment">// For each message to send...
</span>    <span class="code-object">Object</span> requestMessage = ...
    Exchange exchangeToSend = producer.createExchange();
    exchangeToSend().setBody(requestMessage);
    producer.process(exchangeToSend);
    ...

  } <span class="code-keyword">finally</span> {
    <span class="code-comment">// Tidy the producer up.
</span>    producer.stop();
  }
</pre>
</div></div>

<p>In the case of using Apache MINA the producer.stop() invocation will cause the socket
to be closed.</p>
     </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/Fine+Grained+Control+Over+a+Channel">View
Online</a>
       |
       <a href="http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=12321260&revisedVersion=2&originalVersion=1">View
Change</a>
              |
       <a href="http://cwiki.apache.org/confluence/display/CAMEL/Fine+Grained+Control+Over+a+Channel?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message