On 18 Aug 2005, at 16:52, Craig Walls wrote:

I'm still trying to get a handle on how to create a simple POJO-based
component that does nothing but receive a message exchange, log the
fact that it received the message exchange, then allows the exact same
message to be passed to the next service in line--if there is one. (Go
grab a cup of coffee, 'cause this is going to take awhile...)

:)

Here's a simple example component that does that...

http://cvs.servicemix.codehaus.org/servicemix/base/src/main/java/org/ servicemix/components/util/EchoComponent.java?rev=HEAD&view=auto



To that end, I have written a handful of components, all of which
resemble this one:

public class NetworkServiceImpl extends ComponentSupport
    implements MessageExchangeListener {
private static final Log LOG = LogFactory.getLog (BillingServiceImpl.class);

  public NetworkServiceImpl() {}

  public void onMessageExchange(MessageExchange exchange)
      throws MessagingException {
    LOG.info("NETWORK : RECEIVED A MESSAGE");
    NormalizedMessage message = exchange.getMessage("in");
    LOG.info("NETWORK : DISPATCHING MESSAGE");

    InOnly exchange2 = getExchangeFactory().createInOnlyExchange();
    exchange2.setInMessage(message);
    done(exchange2);
  }
}

First of all, this works but is it the correct approach? Or is there a
better way of doing this?

For 'transform' components which take stuff in, do stuff and send on the response, we've the TransformComponentSupport that does all the leg work for you.

Though note that for lots of application functions, you'd probably write that using some POJO based SOAP stack like JAX-WS or Axis or XFire and drop it into the container and do the routing via the JBI binding for the SOAP stack.



Next, I'd really like to *NOT* extend ComponentSupport or PojoSupport,
as I feel that makes my component not-so-POJO. I'm a bit uncomfortable
with implementing MessageExchangeListener, but I can live with that
because it's an interface and not a class.

So, looking through some of the examples, I see that instead of
extending ComponentSupport (or PojoSupport), I can inject a
ServiceMixClient into my component.

Good idea.

The only thing to be careful of is the DefaultServiceMixClient is-a JBI component, so it gets its own DeliveryChannel and you can attach NMR routing rules to the channel. So if your FooService used a ServiceMixClient to send messages it won't use the DeliveryChannel of the component, so you could loose some container-routing information; you're sending as a different component.

I've added a helper class to CVS HEAD called ServiceMixClientFacade which takes a ComponentContext and implements the same ServiceMixClient interface - so if you use that, you'll be using the same underlying component context and delivery channel as if you did the JBI code by hand.

James
-------
http://radio.weblogs.com/0112098/

Reply via email to