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 capabilities 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.

Example POJO Components

First here's how we configure the two components in ServiceMix. Notice that ServiceMix is doing the routing here using destinationService.

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

 

Now lets look at the sender POJO. The sendMessages() method will send messages onto the JBI bus to the destination service specified in the above XML.

{snippet:id=send|lang=java|url=servicemix/smx3/trunk/common/servicemix-components/src/test/java/org/apache/servicemix/components/pojo/MySender.java}

 

Then the receiver processes inbound messages as follows.

{snippet:id=receive|lang=java|url=servicemix/smx3/trunk/common/servicemix-components/src/test/java/org/apache/servicemix/components/pojo/MyReceiver.java}

 

Being even more POJO

The code above may seem a bit too verbose for you. Firstly you can reduce much code by reusing the Component helper classes.

Another option is to be even more POJO-like. If you just want to invoke operations on the JBI bus then there's no need for you to implement the JBI component or lifecycle contract - you can just reuse the Client API.

For example this POJO sends messages into the JBI bus.

{snippet:id=send|lang=java|url=servicemix/smx3/trunk/common/servicemix-components/src/test/java/org/apache/servicemix/components/pojo/PojoSender.java}

 

And this is a POJO receiver which just consumes the messages its given, without explicitly implementing the component or lifecycle interfaces

{snippet:id=receive|lang=java|url=servicemix/smx3/trunk/common/servicemix-components/src/test/java/org/apache/servicemix/components/pojo/PojoReceiver.java}

 

  • No labels

1 Comment

  1. Anonymous

    I'm still struggling to get a basic ServiceMix end to end example up and running using ServiceMix embedded in Geronimo... Would be good to add some additional bits into this doc.

    • Where does the xml configuration file go?  Presumably this ends up in a servicemix.xml file to be read by the lwcontainer?
    • In what package is StringSource defined?  Eclipse can't seem to find the import, although it had no problem with the rest after adding servicemix-jbi-3.0-incubating.jar to the build path
    • Where is this mapped to binding components?  How can I configure/tell whether it is going to use JMS, HTTP etc. for sending/recieving messages
    • How do I wrap all of this up into a deployment unit that I can deploy into Geronimo

    Thanks, M.