Announcement Announcement Module
Collapse
No announcement yet.
Transformer and Converter difference Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Transformer and Converter difference

    Guys,

    May be a stupid question but I somehow getting confused between Transformer and Converter.
    • What is the difference and when,where to prefer one over other?
    • I see that jms:message-driven-channel-adapter has message-converter but actually this can refer to Converter or Transformer both. They seem to be same to me.

    Please pour in your comments. I am basically confused to chose one of them when I have a situtation like

    SI-Component(JMS) --> RequestMsgType1-->SI Component1--> SI-1 replies --> ReplyMsgType1--SI-Component(JMS) --convert/transform the ReplyMsgType1 to RequestMsgTyp2.

    Thanks

  • #2
    In order to understand the difference you need some knowledge of Spring JMS Support.

    JMS messages (in the JMS API) can be of several types, TextMessage, ObjectMessage etc.

    Spring JMS (via the MessageListenerContainer or JmsTemplate) uses a MessageConverter to convert between a POJO and JmsMessage (e.g. String to TextMessage and vice versa). When using Spring JMS, this means the application delegates to the converter rather than dealing with the lower level JMS APIs (and avoids the application having any knowledge of JMS).

    The default message converter is fine unless you want to do something special.

    Since the MDCA uses a MessageListenerContainer under the skins, we expose the ability to plug in a converter; it (or the default) is used to convert from a JmsMessage object to a Spring Integration message payload.

    A transformer, on the other hand, is simply used to transform Spring Integration messages.

    So, more likely than not, if you need a custom transformation, you'd probably use the default message converter and add a transformer to the flow. If, however, you already have a custom message converter, you can plug it in.

    HTH
    Last edited by Gary Russell; Jan 12th, 2011, 02:45 PM.

    Comment


    • #3
      Converters are generally used locally to help an adapter to convert Message to a protocol specific representation and ofter attached to the endpoint/adapter (become part of the adapter). For example in JMS we use converters to convert SI Message to a JMS Message and back.

      Transformers play a more global role within your messaging system and often work together to compliment the work of Converters. For example; Your JMS Converter might expect the SI Message look a certain way to be able to convert it to JMS Message, however the producing endpoint might output such message in a way that is not compatible with the converter simply because such endpoint was developed with no knowledge of who might be consuming the message. So in this case it makes perfect sense to introduce a Transformer that will serve/compliment the downstream adapter by transforming the message to representation that is acceptable by such adapter and its converter.

      Hope that clarifies.

      Comment


      • #4
        Thanks for quick response, Gary and Oleg. Understood! I had implemented Transformer( was on right direction )

        Comment

        Working...
        X