The simplest way to start using ServiceMix to wire together JBI components is via Spring and the XML configuration file mechanism from Spring.

Why use Spring?

Using Spring has quite a few benefits to using the traditional JBI deployment units and configuration file mechanism

  • You don't need separate deployment units and separate XML configuration files for each of your components. Just add a new entry in your Spring XML file to use a new component. So its a more lightweight approach.
  • You don't need to learn a new XML configuration file syntax, just stick to Spring if you already know it
  • You can use the various nice features in Spring (aliasing, using expandable properties to keep login/passwords outside of the XML etc).
  • You can take advantage of POJO support to write light weight JBI components in a POJO style

It's also worth pointing out that a single component can be used in a Spring configuration or in a traditional JBI deployment unit without any code changes so you are free to choose either approach.

The only downsides of using Spring are

  • All components registered via Spring use the same class loader; this may or may not be an issue for you
  • The Spring configuration is ServiceMix specific and not portable to other JBI containers (unless they support a similar mechanism as ServiceMix), though you should be able to embed ServiceMix into any JBI container as a component.

Configuring using Spring XML

So let's see how to wire together a couple of components with Spring. The easiest way to get started is to see an example. The following configuration is taken from these examples.

{snippet:id=example|lang=xml|url=servicemix/smx3/trunk/common/servicemix-components/src/test/resources/org/apache/servicemix/components/pojo/example.xml}

 

We introduce a few new XML tags for JBI configuration, but apart from that you can use all of the regular Spring configuration tags - bean, property, value etc. For example, inside the <container> tag you can configure properties on the JBI container itself using <property> tags. Inside each <component> tag you can configure properties on the component. This allows you to mix and match regular Spring configuration of POJOs with our JBI Spring configuration mechanism.

Routing services together.

As you can see in the above example we use destinationService or destinationInterface or destinationOpertion on a <component> to denote its routing. A component can decide if it wishes how to route requests to another service. If the component just routes to the default output service then these destination settings are used by ServiceMix to route the request.

Using pure Spring

If you don't wish to use the Spring extension XML as shown above you can configure ServiceMix and its components using regular Spring XML. Here's how

  • Configure an instance of the SpringJBIContainer as a regular Spring POJO.
  • Configure the components you wish to deploy as regular Spring POJOs
  • List the components you want to deploy in the componentNames property of the JBI container.

Here is an example of that in action.

Related Documentation

The following tutorial shows how to create JBI components using the Spring Client Toolkit.

  • No labels