Since we're on a major migration process of this website, some component documents here are out of sync right now. In the meantime you may want to look at the early version of the new website
https://camel.apache.org/staging/
We would very much like to receive any feedback on the new site, please join the discussion on the Camel user mailing list.
NMR ComponentThe nmr component is an adapter to the Normalized Message Router (NMR) in ServiceMix, 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. By contrast, the JBI component is intended for use by Camel applications deployed into the ServiceMix JBI container. Installing in Apache ServicemixThe NMR component is provided with Apache ServiceMix. It is not distributed with Camel. To install the NMR component in ServiceMix, enter the following command in the ServiceMix console window: features:install nmr camel-nmr Installing in plain Apache KarafIn plain Karaf the nmr component can also be installed using the servicemix artifacts: features:chooseurl camel <version> 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 ConfigurationYou also need to instantiate the NMR component. You can do this by editing your Spring configuration file, <beans xmlns:osgi="http://www.springframework.org/schema/osgi" ... > ... <bean id="nmr" class="org.apache.servicemix.camel.nmr.ServiceMixComponent"> <property name="nmr"> <osgi:reference interface="org.apache.servicemix.nmr.api.NMR" /> </property> </bean> ... </beans> NMR consumer and producer endpointsThe following code: from("nmr:MyServiceEndpoint") Automatically exposes a new endpoint to the bus with endpoint name When an NMR endpoint appears at the end of a route, for example: to("nmr:MyServiceEndpoint") The messages sent by this producer endpoint are sent to the already deployed NMR endpoint.
URI formatnmr:endpointName URI Options
ExamplesConsumer 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 Producer 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 Using Stream bodiesIf 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 from("nmr:MyEndpoint").streamCaching().to("xslt:transform.xsl", "bean:doSomething"); The stream caching is default enabled, so it is not necessary to set the TestingNMR 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 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"); } }; } } |