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

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?

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...so the above class now changes
to:

public class NetworkServiceImpl
    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 = client.createInOnlyExchange();
    exchange2.setInMessage(message);
    client.done(exchange2);
  }

  private ServiceMixClient client;
  public void setClient(ServiceMixClient client) {
      this.client = client;
  }
}

This makes me feel better. But I can't get it to work, because I can't
seem to come up with the correct Spring wiring to inject the
client. I've tried this:

<container id="jbi">
  <component id="network"
      service="foo:network"
      endpoint="network"
      class="com.habuma.telco.sm.components.NetworkServiceImpl"
      destinationService="foo:install"
      destinationEndpoint="install">
    <property name="client" ref="client" />
  </component>
</container>

<bean id="client"
    class="org.servicemix.client.DefaultServiceMixClient" >
  <constructor-arg ref="jbi" /> <!-- References the container above -->
</bean>

But when I start up my context, Spring complains of a circular
reference (because "jbi" contains "network" which references "client"
which references "jbi" which contains "network" which...). I tried to
do a lazy-init on the "client" bean, but that didn't help much either
(different error, similar circular reference reason for the error).

In all of the packaged examples that contain a "client" bean, I don't
see any of them actually injecting the client into a component as I've
done above. So this makes me question if I'm taking the right approach
or not.

Any help that anyone can provide will be great.

Thanks,
Craig


Reply via email to