camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > ProducerTemplate
Date Fri, 25 May 2012 14:00: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/ProducerTemplate">ProducerTemplate</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~davsclaus">Claus
Ibsen</a>
    </h4>
        <br/>
                         <h4>Changes (4)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >The ProducerTemplate interface allows
you to send message exchanges to endpoints in a variety of different ways to make it easy
to work with Camel [Endpoint] instances from Java code. <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >It can be configured with a default
endpoint if you just want to send lots of messages to the same endpoint; or you can specify
an [Endpoint] or <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">[URI]</span>
<span class="diff-added-words"style="background-color: #dfd;">uri</span> as the
first parameter. <br></td></tr>
            <tr><td class="diff-unchanged" > <br>The *sendBody()* method
allows you to send any object to an endpoint easily. <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >// send with a body and header  <br>template.sendBodyAndHeader(&quot;activemq:MyQueue&quot;,
 <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">
  &quot;&lt;hello&gt;world!&lt;/hello&gt;&quot;, <br></td></tr>
            <tr><td class="diff-changed-lines" >&quot;CustomerRating&quot;,
<span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">&quot;Gold&quot;,</span>
<span class="diff-added-words"style="background-color: #dfd;">&quot;Gold&quot;);</span>
<br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">
  &quot;&lt;hello&gt;world!&lt;/hello&gt;&quot;); <br></td></tr>
            <tr><td class="diff-unchanged" >{code} <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h3><a name="ProducerTemplate-ProducerTemplate"></a>ProducerTemplate</h3>

<p>The ProducerTemplate interface allows you to send message exchanges to endpoints
in a variety of different ways to make it easy to work with Camel <a href="/confluence/display/CAMEL/Endpoint"
title="Endpoint">Endpoint</a> instances from Java code.</p>

<p>It can be configured with a default endpoint if you just want to send lots of messages
to the same endpoint; or you can specify an <a href="/confluence/display/CAMEL/Endpoint"
title="Endpoint">Endpoint</a> or uri as the first parameter.</p>

<p>The <b>sendBody()</b> method allows you to send any object to an endpoint
easily.</p>

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

<span class="code-comment">// send to <span class="code-keyword">default</span>
endpoint
</span>template.sendBody(<span class="code-quote">"&lt;hello&gt;world!&lt;/hello&gt;"</span>);

<span class="code-comment">// send to a specific queue
</span>template.sendBody(<span class="code-quote">"activemq:MyQueue"</span>,
<span class="code-quote">"&lt;hello&gt;world!&lt;/hello&gt;"</span>);

<span class="code-comment">// send with a body and header 
</span>template.sendBodyAndHeader(<span class="code-quote">"activemq:MyQueue"</span>,

   <span class="code-quote">"&lt;hello&gt;world!&lt;/hello&gt;"</span>,
   <span class="code-quote">"CustomerRating"</span>, <span class="code-quote">"Gold"</span>);
</pre>
</div></div>

<p>You can also supply an Exchange or a Processor to customize the exchange</p>

<h3><a name="ProducerTemplate-request%28%29methods"></a>request*() methods</h3>

<p>The send*() methods use the default Message Exchange Pattern (InOnly, InOut etc)
as the endpoint. If you want to explicitly perform a request/response (InOut) you can use
the request*() methods instead of the send*() methods.</p>

<p>e.g. lets invoke an endpoint and get the response</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-object">Object</span> response = template.requestBody(<span
class="code-quote">"&lt;hello/&gt;"</span>);

<span class="code-comment">// you can <span class="code-keyword">cast</span>
the response directly
</span><span class="code-object">String</span> ret = template.requestBody(<span
class="code-quote">"&lt;hello/&gt;"</span>, <span class="code-object">String</span>.class);

<span class="code-comment">// or specify the endpoint directly
</span><span class="code-object">String</span> ret = template.requestBody(<span
class="code-quote">"cxf:bean:HelloWorldService"</span>, <span class="code-quote">"&lt;hello/&gt;"</span>,
<span class="code-object">String</span>.class);
</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/ProducerTemplate">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=98509&revisedVersion=4&originalVersion=3">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/ProducerTemplate?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message