Red Hat Training

A Red Hat training course is available for Red Hat Fuse

Chapter 18. Inter-Bundle Communication with the NMR

Abstract

Red Hat JBoss Fuse provides a non-standard mechanism to support asynchronous messaging, known as the Normalized Message Router (NMR), which is loosely based on the NMR defined in the JBI standard. The NMR has the advantage that it spans both the OSGi container and the JBI container. By contrast, the OSGi Event Admin Service, which also provides asynchronous communication between bundles, can only be used within the OSGi container.

18.1. Architecture of the NMR

Overview

Figure 18.1, “NMR Architecture” shows a general overview of the NMR architecture, which spans both the OSGi container and the JBI container.

Figure 18.1. NMR Architecture

NMR Architecture
In Figure 18.1, “NMR Architecture”, the NMR is represented as a horizontal graphical element in order to emphasize its role linking together various application bundles. In practice, however, the NMR is deployed as a collection of bundles, just like any other application in the OSGi container.

NMR

The Red Hat JBoss Fuse NMR is a general-purpose message bus used for transmitting messages between bundles in the OSGi container. It is modelled on the Normalized Message Router (NMR) defined in the Java Business Integration (JBI) specification. Hence, the JBoss Fuse NMR can be used to transmit XML messages, optionally augmented with properties and attachments.

NMR for OSGi

Unlike the standard NMR, however, the JBoss Fuse NMR is not restricted to the JBI container. You can use the NMR to transmit messages inside the OSGi container or, if the JBI container is also deployed, to transmit messages between the two containers.

Normalized messages in the JBI container

A key feature of the NMR message bus is that messages are transmitted in a standard, normalized form. The JBI standard defines a normalized message, which is based on the Web Services Description Language (WSDL) message format (both WSDL 1.1 and WSDL 2.0 formats are supported). A complete normalized message has the following aspects:
  • Content—the main content of a normalized message must be in XML format, where the layout of a particular message is defined in a WSDL service description.
  • Attachments—for sending binary content, you can add attachments to the normalized message.
  • Properties—consist of name/value pairs.
  • Security subject—identifies the sender, if security features are enabled.

Normalized messages in the OSGi container

In the OSGi container, normalized messages have a standard layout, as follows:
  • Content—the main content of a normalized message, which can be in any format.
  • Attachments—for sending binary attachments.
  • Properties—consist of name/value pairs.
  • Security subject—identifies the sender, if security features are enabled.
Note
When transmitting messages solely within the OSGi container, normalization of message content is not enforced. That is, the OSGi container does not impose any restrictions on the format of the message content. If messages are transmitted to an endpoint in the JBI container, however, message normalization must be observed.

NMR API

Red Hat JBoss Fuse provides a simple Java API for accessing the NMR. You can use this API to define endpoints that process messages received from the NMR and you can write clients that send messages to NMR endpoints. To see how to use this API in practice, take a look at the examples/nmr demonstration code.

NMR component for Apache Camel

To enable integration with the NMR, Apache Camel provides an NMR component, which lets you define NMR endpoints either at the beginning (for example, as in from("nmr:ExampleEndpoint")) or at the end (for example, to("nmr:ExampleEndpoint")) of a route. For full details of how to use the NMR component, see Section 18.2, “The Apache Camel NMR Component”.
Note
The NMR component is designed specifically for integrating Apache Camel with the NMR within the OSGi container. If you deploy a Apache Camel application in the JBI container, however, NMR integration is provided by the JBI component. The NMR component (for use in an OSGi context) is conventionally identified by the nmr URI scheme, whereas the JBI component (for use in a JBI context) is conventionally identified by the jbi URI scheme.