LibraryLink ToToggle FramesPrintFeedback

Using the NMR Component

The NMR component is an adapter to the NMR, which is a general-purpose message bus that applications can use in order to communicate within the FUSE ESB OSGi container. It is modelled on the Normalized Message Router (NMR) defined in the Java Business Integration (JBI) specification. Hence, the FUSE ESB NMR can be used to transmit XML messages, along with properties and attachments. Unlike the standard NMR, however, the FUSE ESB NMR is not restricted to the JBI container. You can use the NMR to transmit messages inside the OSGi container, even if JBI is not deployed. Moreover, if you do deploy the JBI container, you can use the NMR for communicating between the two containers.

The NMR component is installed in FUSE ESB as an OSGi bundle. The NMR component gets installed along with the NMR feature, which you can install by entering the following command:

features install nmr

Normally, the NMR feature is pre-installed in the OSGi container. In addition to installing the NMR feature, however, you also need to edit your application's Spring XML configuration file, META-INF/spring/*.xml, in order to instantiate the NMR component. The following XML import inserts a chunk of XML that takes care of instantiating the NMR component:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans" ... >
  ...
  <import resource="classpath:org/apache/servicemix/camel/camel-nmr.xml" />
  ...
</beans>

Because this import statement references the external package, org.apache.servicemix.camel, you also need to import this package in the Import-Package bundle header—see Example 1.6 for details.

The NMR component enables you to create and to reference endpoints using a JBI style of addressing. The general form of an NMR endpoint URI is as follows:

nmr:JBIAddressingURI

Where JBIAddressingURI conforms to the URI format described in ServiceMix URIs.

By default, an NMR endpoint supports oneway exchanges (In messages only). If you want to enable an NMR endpoint to send back a reply, you must explicitly enable this using the mep query option. To enable the InOut message exchange protocol on an NMR endpoint, simply append ?mep="in-out" to the URI. For example:

nmr:ExampleRouter?mep=in-out

The camel-nmr demonstration is located in the following directory:

InstallDir/examples/camel-nmr

The demonstration defines two routes in XML, where the routes are joined together using an NMR endpoint. The first route is defined as follows:

The second route is defined as follows:

The route is deployed into the FUSE ESB container as an OSGi bundle.

Example 1.5 shows the routes for the camel-nmr demonstration, taken from the Spring XML configuration file, META-INF/spring/beans.xml.


1

This Spring import element imports a snippet of XML that instantiates and initializes the NMR component. The NMR component is exceptional in this respect: for most of the non-core components, you can put the relevant XML snippet directly into your Spring configuration file instead of importing it.

The location of the XML snippet is specified using the classpath URI, classpath:org/apache/servicemix/camel/camel-nmr.xml, which indicates that the XML file can be found on the current CLASSPATH. As a matter of fact, the camel-nmr.xml file is located in a separate bundle: that is, it is part of the org.apache.servicemix.camel.component bundle. Hence, it is necessary to import the org.apache.servicemix.camel bundle, in order to make this XML file accessible (see Example 1.6 for details of how this is done).

2

At the end of the first route, messages are sent to the NMR endpoint, nmr:ExampleRouter.

3

When you specify an NMR endpoint in the uri attribute of the <from> tag, a new NMR endpoint is created by the NMR component. In this example, the <from> tag implicitly creates the NMR endpoint, nmr:ExampleRouter, which is then capable of receiving the messages sent by the first route.

[Note]Note

The NMR is a general purpose message bus that operates independently of the JBI container. Hence, it is possible to create NMR endpoints outside the JBI container, as is done in this example.

The bundle headers are defined in the JAR's manifest file, which is stored in the following location:

META-INF/MANIFEST.MF

Example 1.6 shows the manifest for the camel-nmr bundle (for a more detailed explanation of these manifest entries, see Example 1.3).


The important entries are the bundle headers that affect the interaction between the bundle and the OSGi container and these are, as follows: