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).
Its 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).
Getting started
So lets see how to wire together a couple of components with Spring. You need to do the following...
- 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.