Announcement Announcement Module
Collapse
No announcement yet.
Using the Interface MessageConverter Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using the Interface MessageConverter

    Hi,

    I am using org.springframework.amqp.rabbit.listener.adapter.M essageListenerAdapter so that my messageHandler class's handleMessage gets called whenever a message gets published on RabbitMQ's exchange. Till now it was simple string so there was no messageConverter needed, but now I want that an 'MessageInfo' object gets passed and my messageHandler class's handleMessage should be called. What changes will I have to do for that?

    perhaps, in other words,

    my previous config(Text is passed and handled) was :
    ===================================

    <bean id="messageHandlerAdaptor" class="org.springframework.amqp.rabbit.listener.ad apter.MessageListenerAdapter">
    <constructor-arg ref="messageHandler" />
    </bean>

    I guess my new config('MessageInfo' object should be passed and handled) should be :
    ========================
    <bean id="messageHandlerAdaptor" class="org.springframework.amqp.rabbit.listener.ad apter.MessageListenerAdapter">
    <constructor-arg ref="messageHandler" />
    <property name="messageConverter" ref="messageConverter" />
    </bean>

    <bean id="messageConverter" class="">
    ??
    </bean>

    Many Thanks,
    Kshitiz

  • #2
    What type of serialization would you prefer to use? Two common options that we do support (via out-of-the-box MessageConverter implementations) are JSON and XML. Of course, you can always implement the MessageConverter interface yourself.

    Comment


    • #3
      Thanks Mark,

      Actually it is a message that can be easily represented in the form of a XML. Should I send that as a simple string? but then will I have keep the XSD schema files ready at both producer's (to marshal) and consumer's ends (to unmarshal) and make the java objects on my own....

      Is XML serialization mentioned by you a similar process or a different one? In case it's different, how I can I leverage that ?

      P.S.-> I am currently working on a notification engine POC containing Publisher->Restlet->Spring Integration->SpringAMQP->RabbitMQ->Consumers, so I will be asking too many questions, please bear with me.

      Regards,
      Kshitiz

      Comment


      • #4
        Spring AMQP provides a MarshallingMessageConverter implementation that delegates to any Spring OXM Marshaller/Unmarshaller implementation.

        You can learn more about Spring OXM here:
        http://static.springsource.org/sprin...rence.html#oxm

        Hope that helps.
        -Mark

        Comment


        • #5
          Thanks Mark,

          I will try using that.

          But first I would like to have your suggestion in my scenario. Here both the publisher and the consumer are going to be the parts of my "own" system, so is it okay if I send the XML as a String simply and parse it at the consumer end using DOM/SAX parser(s)? What do you suggest ?

          and by any chance, is there any existing example out there using spring amqp MarshallingMessageConverter implementation that delegates to any Spring OXM Marshaller/Unmarshaller implementation?

          Regards,
          Kshitiz

          Comment


          • #6
            JSON Marshalling

            So I am trying to do the same thing.

            My messages are JSON messages. What I would like to do is take a value out of the JSON message and then use that to determine the specific class to map the message to. However, I am struggling with getting the ClassMapper part of the JSONMessageConvertor configured correctly.

            What information can I provide in order to help troubleshoot my issue? And is it possible to change class types based on a value in the JSON?

            Comment

            Working...
            X