이 콘텐츠는 선택한 언어로 제공되지 않습니다.

Chapter 88. NMR


NMR Component

The 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 Servicemix

The NMR component is provided with Apache ServiceMix. It is not distributed with Apache Camel. To install the NMR component in ServiceMix, enter the following command in the ServiceMix console window:
features:install nmr camel-nmr
Copy to Clipboard Toggle word wrap

Installing in plain Apache Karaf

In 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
Copy to Clipboard Toggle word wrap

Configuration

You also need to instantiate the NMR component. You can do this by editing your Spring configuration file, META-INF/spring/*.xml, and adding the following bean instance:
<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>
Copy to Clipboard Toggle word wrap

NMR consumer and producer endpoints

The following code:
from("nmr:MyServiceEndpoint")
Copy to Clipboard Toggle word wrap
Automatically exposes a new endpoint to the bus with endpoint name MyServiceEndpoint (see #URI-format).
When an NMR endpoint appears at the end of a route, for example:
to("nmr:MyServiceEndpoint")
Copy to Clipboard Toggle word wrap
The messages sent by this producer endpoint are sent to the already deployed NMR endpoint.

URI format

An NMR endpoint has the following URI fomat:
nmr:endpointName
Copy to Clipboard Toggle word wrap

URI Options

An NMR endpoint supports the following options:
Expand
Option Default Value Description
synchronous false When this is set to true 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
runAsSubject false Apache ServiceMix 4.4: When this is set to true 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)
timeout 0 Apache ServiceMix 4.4: 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.
throwExceptionOnFailure true Apache ServiceMix 4.5.2: When this is set to false then NMR's exceptions (like TimeoutException) will be consumed silently.

Examples

Consumer:
// consume nmr exchanges asynchronously
from("nmr:MyServiceEndpoint") 
// consume nmr exchanges synchronously and use the same thread as  defined by NMR ThreadPool
from("nmr:MyServiceEndpoint?synchronous=true").to()
Copy to Clipboard Toggle word wrap
Producer:
// produce nmr exchanges asynchronously
from()...to("nmr:MyServiceEndpoint") 
// produce nmr exchanges synchronously and wait till 10s to receive response
from()...to("nmr:MyServiceEndpoint?timeout=10000")
Copy to Clipboard Toggle word wrap

Using Stream bodies

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 DEBUG logging, the body is usually logged and thus read. To deal with this, Camel has a streamCaching option that can cache the stream, enabling you to read it multiple times.
from("nmr:MyEndpoint").streamCaching().to("xslt:transform.xsl", "bean:doSomething");
Copy to Clipboard Toggle word wrap
From Camel 1.5 onwards, the stream caching is default enabled, so it is not necessary to set the streamCaching() option. In Camel 2.0 we store big input streams (by default, over 64K) in a temp file using CachedOutputStream. When you close the input stream, the temp file will be deleted.

Testing

NMR camel routes can be tested using the Apache Camel unit test approach even if they will be deployed next in different bundles in an OSGi runtime. With this aim in view, you will extend the ServiceMixNMR Mock class, org.apache.servicemix.camel.nmr.AbstractComponentTest, which will create an NMR bus, register the Apache Camel NMR Component and the endpoints defined into the Apache Camel routes.
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 {
        returnnew RouteBuilder() {

            @Override
            public void configure() throws Exception {
                from("direct:simple").to("nmr:simple");
                from("nmr:simple?synchronous=true").to("mock:simple");
            }
        };
    }
}
Copy to Clipboard Toggle word wrap
맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat