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 Sun, 27 Nov 2011 17: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/Fine+Grained+Control+Over+a+Channel">Fine
Grained Control Over a Channel</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~bibryam">Bilgin
Ibryam</a>
    </h4>
        <br/>
                         <h4>Changes (2)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-changed-lines" ><span class="diff-changed-words">h<span
class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">1</span><span
class="diff-added-chars"style="background-color: #dfd;">2</span>.</span> Introduction
<br></td></tr>
            <tr><td class="diff-unchanged" >When sending an [Exchange] to an [Endpoint]
you can either use a [Route|Routes] or a [ProducerTemplate]. 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 [MINA] 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. <br> <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-changed-words">h<span
class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">1</span><span
class="diff-added-chars"style="background-color: #dfd;">2</span>.</span> Using
a Producer <br></td></tr>
            <tr><td class="diff-unchanged" >To achieve fine grained control over
sending exchanges you will need to program directly to a Producer. Your code will look similar
to: <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="FineGrainedControlOveraChannel-Introduction"></a>Introduction</h2>
<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>

<h2><a name="FineGrainedControlOveraChannel-UsingaProducer"></a>Using a
Producer</h2>
<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="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Fine+Grained+Control+Over+a+Channel">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=12321260&revisedVersion=3&originalVersion=2">View
Changes</a>
                |
        <a href="https://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