camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject [CONF] Apache Camel > Fine Grained Control Over a Channel
Date Tue, 26 Jan 2010 10:13:00 GMT
    <base href="">
            <link rel="stylesheet" href="/confluence/s/1519/1/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
     <h2><a href="">Fine
Grained Control Over a Channel</a></h2>
     <h4>Page <b>edited</b> by             <a href="">Christopher
     <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
<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
</span>  Endpoint endpoint = camelContext.getEndpoint(<span class="code-quote">"someuri:etc"</span>);
  Producer producer = endpoint.createProducer();

  <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();

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

<p>In the case of using Apache MINA the producer.stop() invocation will cause the socket
to be closed.</p>
     <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href=""
class="grey">Change Notification Preferences</a>

       <a href="">View
       <a href="">View
       <a href=";showCommentArea=true#addcomment">Add

View raw message