camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Piotr Klimczak (Confluence)" <conflue...@apache.org>
Subject [CONF] Apache Camel > NMR
Date Mon, 09 Sep 2013 13:50:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/en/2176/1/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/NMR">NMR</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~nannou9">Piotr
Klimczak</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" >{code} <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >h3. <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
</span> Installing in plain Apache Karaf <br></td></tr>
            <tr><td class="diff-unchanged" > <br>In plain Karaf the nmr
component can also be installed using the servicemix artifacts: <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >{code} <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >Automatically exposes a new endpoint
to the bus with endpoint name {{MyServiceEndpoint}} (see <span class="diff-changed-words">[<span
class="diff-added-chars"style="background-color: #dfd;">URI-format|</span>#URI-format]).</span>
<br></td></tr>
            <tr><td class="diff-unchanged" > <br>When an NMR endpoint appears
at the end of a route, for example: <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >{div:class=confluenceTableSmall} <br>||
Option || Default Value || Description || <br></td></tr>
            <tr><td class="diff-changed-lines" >| {{runAsSubject}} | {{false}}
| *Apache ServiceMix 4.4:* When this is set to <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">*{{true}}*</span>
<span class="diff-added-words"style="background-color: #dfd;">{{{*}true{*}}}</span>
on a consumer endpoint, the endpoint will be invoked on behalf of the {{Subject}} that is
set on the {{Exchange}} (i.e. the call to {{Subject.getSubject(AccessControlContext)}} will
return the {{Subject}} instance) | <br>| {{synchronous}} | {{false}} | When this is
set to <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">*{{true}}*</span>
<span class="diff-added-words"style="background-color: #dfd;">{{{*}true{*}}}</span>
on a consumer endpoint, an incoming, synchronous NMR Exchange will be handled on the sender&#39;s
thread instead of being handled on a new thread of the NMR endpoint&#39;s thread pool
| <br></td></tr>
            <tr><td class="diff-unchanged" >| {{timeout}} | {{0}} | *Apache ServiceMix
4.4:* When this is set to a value greater than 0, the producer endpoint will timeout if it
doesn&#39;t receive a response from the NMR within the given timeout period (in milliseconds).
 Configuring a timeout value will switch to using synchronous interactions with the NMR instead
of the usual asynchronous messaging. | <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">|
{{throwExceptionOnFailure}} | true | *Apache ServiceMix 4.5.2:* When this is set to {{{*}false{*}}}
then NMR&#39;s exceptions (like TimeoutException) will be consumed silently. | <br></td></tr>
            <tr><td class="diff-unchanged" >{div} <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="NMR-NMRComponent"></a>NMR Component</h2>

<p>The <b>nmr</b> component is an adapter to the Normalized Message Router
(NMR) in <a href="http://servicemix.apache.org/home.html" class="external-link" rel="nofollow">ServiceMix</a>,
which is intended for use by Camel applications deployed directly into the OSGi container.
You can exchange objects with NMR and not only XML like this is the case with the JBI specification.
The interest of this component is that you can interconnect camel routes deployed in different
OSGI bundles.</p>

<p>By contrast, the <a href="/confluence/display/CAMEL/JBI" title="JBI">JBI</a>
component is intended for use by Camel applications deployed into the ServiceMix JBI container.</p>

<h3><a name="NMR-InstallinginApacheServicemix"></a>Installing in Apache
Servicemix</h3>

<p>The NMR component is provided with Apache ServiceMix. It is <b>not</b>
distributed with Camel. To install the NMR component in ServiceMix, enter the following command
in the ServiceMix console window:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
features:install nmr camel-nmr
</pre>
</div></div>

<h3><a name="NMR-InstallinginplainApacheKaraf"></a>Installing in plain Apache
Karaf</h3>

<p>In plain Karaf the nmr component can also be installed using the servicemix artifacts:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
features:chooseurl camel &lt;version&gt;
features:addurl mvn:org.apache.servicemix.nmr/apache-servicemix-nmr/1.5.0/xml/features
features:install camel-blueprint nmr camel-nmr
install -s mvn:org.apache.servicemix.camel/org.apache.servicemix.camel.component/4.4.2
</pre>
</div></div>

<h3><a name="NMR-Configuration"></a>Configuration</h3>

<p>You also need to instantiate the NMR component. You can do this by editing your Spring
configuration file, <tt>META-INF/spring/*.xml</tt>, and adding the following <tt>bean</tt>
instance:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
&lt;beans xmlns:osgi="http://www.springframework.org/schema/osgi" ... &gt;
    ...
    &lt;bean id="nmr" class="org.apache.servicemix.camel.nmr.ServiceMixComponent"&gt;
        &lt;property name="nmr"&gt;
            &lt;osgi:reference interface="org.apache.servicemix.nmr.api.NMR" /&gt;
        &lt;/property&gt;
    &lt;/bean&gt;
    ...
&lt;/beans&gt;
</pre>
</div></div>

<h3><a name="NMR-NMRconsumerandproducerendpoints"></a>NMR consumer and producer
endpoints</h3>

<p>The following code:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
from("nmr:MyServiceEndpoint")
</pre>
</div></div>

<p>Automatically exposes a new endpoint to the bus with endpoint name <tt>MyServiceEndpoint</tt>
(see <a href="#NMR-URIformat">URI-format</a>).</p>

<p>When an NMR endpoint appears at the end of a route, for example:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
to("nmr:MyServiceEndpoint")
</pre>
</div></div>

<p>The messages sent by this producer endpoint are sent to the already deployed NMR
endpoint.</p>

<p><a name="NMR-URIformat"></a></p>

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

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
nmr:endpointName
</pre>
</div></div>

<h4><a name="NMR-URIOptions"></a>URI Options</h4>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Option </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>runAsSubject</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Apache ServiceMix 4.4:</b> When this is set
to <tt><b>true</b></tt> on a consumer endpoint, the endpoint will
be invoked on behalf of the <tt>Subject</tt> that is set on the <tt>Exchange</tt>
(i.e. the call to <tt>Subject.getSubject(AccessControlContext)</tt> will return
the <tt>Subject</tt> instance) </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>synchronous</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> When this is set to <tt><b>true</b></tt>
on a consumer endpoint, an incoming, synchronous NMR Exchange will be handled on the sender's
thread instead of being handled on a new thread of the NMR endpoint's thread pool </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>timeout</tt> </td>
<td class='confluenceTd'> <tt>0</tt> </td>
<td class='confluenceTd'> <b>Apache ServiceMix 4.4:</b> When this is set
to a value greater than 0, the producer endpoint will timeout if it doesn't receive a response
from the NMR within the given timeout period (in milliseconds).  Configuring a timeout value
will switch to using synchronous interactions with the NMR instead of the usual asynchronous
messaging. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>throwExceptionOnFailure</tt> </td>
<td class='confluenceTd'> true </td>
<td class='confluenceTd'> <b>Apache ServiceMix 4.5.2:</b> When this is set
to <tt><b>false</b></tt> then NMR's exceptions (like TimeoutException)
will be consumed silently. </td>
</tr>
</tbody></table>
</div>
</div>


<h4><a name="NMR-Examples"></a>Examples</h4>

<p>Consumer</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
from("nmr:MyServiceEndpoint") // consume nmr exchanges asynchronously
from("nmr:MyServiceEndpoint?synchronous=true").to() // consume nmr exchanges synchronously
and use the same thread as defined by NMR ThreadPool
</pre>
</div></div>

<p>Producer</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
from()...to("nmr:MyServiceEndpoint") // produce nmr exchanges asynchronously
from()...to("nmr:MyServiceEndpoint?timeout=10000") // produce nmr exchanges synchronously
and wait till 10s to receive response
</pre>
</div></div>

<h3><a name="NMR-UsingStreambodies"></a>Using Stream bodies</h3>

<p>If you are using a stream type as the message body, you should be aware that a stream
is only capable of being read once. So if you enable <tt>DEBUG</tt> logging, the
body is usually logged and thus read. To deal with this, Camel has a <tt>streamCaching</tt>
option that can cache the stream, enabling you to read it multiple times.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
from("nmr:MyEndpoint").streamCaching().to("xslt:transform.xsl", "bean:doSomething");
</pre>
</div></div>

<p>The stream caching is default enabled, so it is not necessary to set the <tt>streamCaching()</tt>
option.<br/>
We store big input streams (by default, over 64K) in a <tt>temp</tt> file using
<tt>CachedOutputStream</tt>. When you close the input stream, the temp file will
be deleted.</p>

<h4><a name="NMR-Testing"></a>Testing</h4>

<p>NMR camel routes can be tested using the camel unit test approach even if they will
be deployed next in different bundles on an OSGI runtime. With this aim in view, you will
extend the ServiceMixNMR Mock class <tt>org.apache.servicemix.camel.nmr.AbstractComponentTest</tt>
which will create a NMR bus, register the Camel NMR Component and the endpoints defined into
the Camel routes.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
public class ExchangeUsingNMRTest extends AbstractComponentTest {

    @Test
    public void testProcessing() throws InterruptedException {
        MockEndpoint mock = getMockEndpoint("mock:simple");
        mock.expectedBodiesReceived("Simple message body");

        template.sendBody("direct:simple", "Simple message body");

        assertMockEndpointsSatisfied();

    }

    @Override
    protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {

            @Override
            public void configure() throws Exception {
                from("direct:simple").to("nmr:simple");
                from("nmr:simple?synchronous=true").to("mock:simple");
            }
        };
    }
}
</pre>
</div></div>


<h3><a name="NMR-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>

    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;" class="grey">
                        <a href="https://cwiki.apache.org/confluence/users/removespacenotification.action?spaceKey=CAMEL">Stop
watching space</a>
            <span style="padding: 0px 5px;">|</span>
                <a href="https://cwiki.apache.org/confluence/users/editmyemailsettings.action">Change
email notification preferences</a>
</div>
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/NMR">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=3473729&revisedVersion=12&originalVersion=11">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/NMR?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message