Announcement Announcement Module
No announcement yet.
passing raw message to MessageListenerAdapter handler method fails Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • passing raw message to MessageListenerAdapter handler method fails

    MessageListenerAdapter API says that handler methods can accept raw Method types. When I send Message with custom properties in the Producer as

    Message message = new Message("<xml>NST description</xml>".getBytes(),
    and then define handler method as
    public void handleMessage(Message NSTmessage) {
    I am getting the following exception:
    org.springframework.amqp.rabbit.listener.ListenerE xecutionFailedException: Failed to invoke target method 'handleMessage' with argument type = [class [B], value = [{[[email protected]}]

    Please help! When I do same thing with Strings, it works.

  • #2
    Try setting the content-type header to text/xml.


    • #3

      By default, the MLA will use a SimpleMessageConverter which will convert to a String when there is a content-type starting with 'text'. It also supports 'application/x-java-serialized-object'.

      For an unrecognized (or no) content-type, it will extract the byte[] payload, which is what you are seeing.

      In the JavaDoc you referenced, notice this comment...

      By default, the content of incoming Rabbit messages gets extracted before being passed into the target listener method, to let the target method operate on message content types such as String or byte array instead of the raw Message. Message type conversion is delegated to a Spring AMQ MessageConverter.

      By default, a SimpleMessageConverter will be used.

      (If you do not want such automatic message conversion taking place, then be sure to set the MessageConverter to null.)
      So, to get a raw message, you must set the MLA's messageConverter to null, either by the constructor, or setter.