You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »

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.

JBI POJO support

ServiceMix provides support for JBI POJOs in addition to the usual JBI Components. JBI Components are maybe not as lightweight as they could be; there's a bunch of methods on there for dealing with metadata, management and capability management along with a lifecycle object.

ServiceMix introduces the idea of a JBI POJO which is any Java object which implements the ComponentLifeCycle interface and uses dependency injection to configure itself. Adding an instance of ComponentLifeCycle to the SpringJBIContainer will automatically wrap the POJO in a JBI ComponentAdaptor so that it faithfully obeys the JBI Component contract.

This means you can write JBI POJOs to be deployed by Spring without deriving from some helper base class like ServiceMix's ComponentSupport so that your POJO has no dependency other than on the JBI APIs and then let ServiceMix take care of more of the plumbing for you.

To see this in use, take a look at this example. The Spring XML looks about the same as the above example, the difference is the implementation classes.

  • No labels