Event listeners
The NMR has a rich event API that can be used to receive all sort of notifications about what's happening in the NMR.
Currently, two types of listeners are defined:
org.apache.servicemix.nmr.api.event.EndpointListener
org.apache.servicemix.nmr.api.event.ExchangeListener
Endpoint Listener
API
The EndpointListener defined two methods:
endpointRegistered is called whenever a new endpoint is registered with the NMR
endpointUnregistered is called whenever an existing endpoint is unregistered
public interface EndpointListener {
void endpointRegistered(InternalEndpoint endpoint);
void endpointUnregistered(InternalEndpoint endpoint);
}
Registering EndpointListener
An EndpointListener can be registered directly with the NMR:
nmr.getListenerRegistry().register(listener, null);
The recommended way of registering an EndpointListener is by adding it to the OSGi Service Registry, e.g. using a Blueprint XML file:
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0">
<bean id="myListener" class="..."/>
<service ref="myListener">
<interfaces>
<value>org.apache.servicemix.nmr.api.event.EndpointListener</value>
<value>org.apache.servicemix.nmr.api.event.Listener</value>
</interfaces>
</service>
</blueprint>
Example
An example of using an endpoint listener is shipped as part of the ServiceMix distribution. It can be found in the examples/interceptors/endpoint directory.
ExchangeListener
API
The ExchangeListener defined two methods:
exchangeSent is called whenever an exchange is sent to the NMR for delivery
exchangeDelivered is called whenever an exchange is being delivered to an endpoint
exchangeFailed is called when a failure occurs while handling an exchange
public interface ExchangeListener {
void exchangeSent(Exchange exchange);
void exchangeDelivered(Exchange exchange);
void exchangeFailed(Exchange exchange);
}
Registering ExchangeListener
An ExchangeListener can be registered directly with the NMR:
nmr.getListenerRegistry().register(listener, null);
The recommended way of registering an ExchangeListener is by adding it to the OSGi Service Registry, e.g. using a Blueprint XML file:
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0">
<bean id="myListener" class="..."/>
<service ref="myListener">
<interfaces>
<value>org.apache.servicemix.nmr.api.event.ExchangeListener</value>
<value>org.apache.servicemix.nmr.api.event.Listener</value>
</interfaces>
</service>
</blueprint>
Example
An example of using an exchange listener is shipped as part of the ServiceMix distribution. It can be found in the examples/interceptors/exchange directory.