Wiki Markup |
---|
{scrollbar} |
Anchor | ||||
---|---|---|---|---|
|
9. Interceptors
ServiceMix NMR has several ways to intercept exchanges between two endpoints.
Exchange listeners
The first one can be achiveved by using the eventing API which allows listeners to be registered into the NMR. Those listeners will be called synchronously each time an exchange is sent or received anywhere within the NMR. This enables the creation of all kind of interception.
Wires
Another kind of interception can be achieved using Wires. A wire provides a means of linking another set of endpoint properties to an existing endpoint.
A Wire defines two maps:
Code Block |
---|
public interface Wire { Map<String, ?> getFrom(); Map<String, ?> getTo(); } |
The address of the target endpoint for a given exchange is provided using a Reference object. Such Reference object are often retrieved from the NMR using EndpointRegistry#lookup(Map<String, ?> props)
method. When this method is called, the registered wires will be checked to see if the from
map of the wire matches the argument of the lookup method. If the wire matches, the to
map of the wire will be used instead of the original values. This will in effect route the exchange to a different endpoint.
However, note that the original map values is lost in the process.
To register a Wire in the NMR, you can either register it explicitely using the following:
Code Block |
---|
nmr.getWireRegistry().register(ServiceHelper.createWire(from, to)); |
Alternatively, you can register the Wire as an OSGi service and the NMR will automatically register it in the WireRegistry.
Future
Based on exchange listeners, we plan to provide an easy way to register interceptors in the future. Those should provide an easy way of filtering exchanges and process them. In addition, we also plan to implement an Interceptor Endpoint concept. Those are endpoints that would be called during the interception of a given exchange allowing processing the exchange without altering the flow explicitely. See SMX4NMR-23.
[#top}
Wiki Markup |
---|
{scrollbar} |