Monday, September 1, 2008

Transformers vs. Components - Take 2

In my previous article, I claimed that one of the main criteria for which Mule artifact to choose is the multiplicity of the inbound and outbound messages. I've been thinking about it and I want to add two more points:

  • Transformers are one instance per endpoint reference. This means that even if you use pooled components, all messages go through single transformer instance. In such case, you need to make sure that the transformer is threadsafe (which is not true if it is holding a JDBC connection or Hibernate session). The components do not have to be threadsafe, though if you are injecting some shared state you still need to properly synchronize the access to it.
  • Mule2 services allow you to configure different ways of instantiating the component (singleton, pooled, looked up from Spring/JNDI/OSGi/etc.). In contrast, all transformers defined using the mule-core namespace are prototype-scoped.
  • I actualy agree that direct database access belongs in a component. I still think that accessing a cache is kindof a gray area though.


Antoine Borg said...

Hi Dimitar,

When you mention that "Transfomers are one per endpoint", did you mean that one instance is available per endpoint? When I first read it, I thought you meant that you can only place one transformer on an endpoint which is not the case. However, after re-reading it, I think you were talking about instances.

I agree that accessing a cache in a transformer is a gray area. I would go as far as saying that you would choose a service over a transformer for cache-based operations based on the length of time required to perform the transformation. Lengthier operations, if services, may perform better because of the SEDA model.


Dimitar said...

Yes, that's what I meant (thanks for noticing). Hope that the edited version makes more sense.

Agree on the second paragraph.

About Me: check my blogger profile for details.

About You: you've been tracked by Google Analytics and Google Feed Burner and Statcounter. If you feel this violates your privacy, feel free to disable your JavaScript for this domain.

Creative Commons License This work is licensed under a Creative Commons Attribution 3.0 Unported License.