To make it simpler to use as an end user, we've created a JBI Client API which makes it easy to work with any JBI container and other JBI components.
...
This example uses a specific service to invoke
...
In this example, we assume that the JBI container will have setup a default routing connection for our client, so we don't have to worry about specifying the endpoint.
...
Invoking services
...
Working with URIs and Destinations
...
The following shows how to work with InOnly for one way messaging
...
...
Or using InOut for request-response
...
Simpler one-way messaging with Destinations
For one-way messaging its sometimes simpler to just work with a Message instance (you can always refer to the MessageExchange via the getExchange() method if need be). For example
...
...
For more detail see the unit test case
Using the POJO methods
We provide a few helper POJO based methods to allow you to use JBI using regular POJOs to hide some of the XML marshaling detail. Then you can use a plugable Marshaler to map your POJOs to JAXP Sources.
...
This example uses a specific service to invoke
...
In this example, we assume that the JBI container will have setup a default routing connection for our client, so we don't have to worry about specifying the endpoint.
...
...
Invoking services
...
...
Configuring the ServiceMixClient
...
Here's an example of using a basic client...
...
...
Note that the jbi bean reference is the ServiceMix JBI container.
This example creates a client which is hard-wired to default to a specific service when an invocation is performed.
...
If you have access to a ComponentContext
If you are inside a JBI component you can create a ServiceMixClient as follows
...
If you want to access a remote ServiceMix instance
If you want to create a ServiceMixClient to access services on a remote ServiceMix instance, you can use the RemoteServiceMixClient. The constructor arguments shown below is the URI for connecting to ServiceMix's embedded ActiveMQ instance. This only works if the remote instance has the JMS Flow enabled.
...
If you are using Spring, this becomes
...
Using ClientFactory
Starting from 3.0-M3, you can retrieve a ClientFactory from JNDI.
...
Note that creating client is somewhat expensive, so it's best to create a client once and reuse it.