Announcement Announcement Module
No announcement yet.
JmsGateway fails when used with in request/reply mode Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • JmsGateway fails when used with in request/reply mode


    I need to read a message from a JMS queue, do some processing and then send the result as a reply to another JMS queue.

    To achieve this, I am using the JmsGateway (I use the SI version M6). Please find below the my JmsGateway configuration:
    <integration:direct-channel id="errorMessages"/>
    <integration:jms-gateway id="jmsGateway" request-channel="errorMessages" connection-factory="jndiConnectionFactory" destination-name="JMS_QUEUE" acknowledge="transacted" max-concurrent-consumers="1" expect-reply="true"/>
    <integration:service-activator input-channel="errorMessages" ref="errorProcessor" method="processError"/>
    <bean id="vitErrorProcessor" class=""/>
    I get the following exception:
    org.springframework.integration.message.MessagingException: expected a 'org.springframework.integration.message.Message', but received 'class java.util.HashMap'
    	at org.springframework.integration.adapter.jms.HeaderMappingMessageConverter.toMessage(
    	at org.springframework.jms.listener.adapter.MessageListenerAdapter.buildMessage(
    	at org.springframework.jms.listener.adapter.MessageListenerAdapter.handleResult(
    	at org.springframework.jms.listener.adapter.MessageListenerAdapter.onMessage(
    	at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(
    	at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(
    	at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(
    	at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(
    	at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(
    	at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(
    	at org.springframework.jms.listener.DefaultMessageListenerContainer$
    Thinking that my configuration is correct (maybe this is a wrong assumtion), I tried debugging to see where could be the problem and I think I found the potential bug. When intializing the JmsGateway, the listener method is set to sendAndReceive (see line 135 listener.setDefaultListenerMethod(this.expectReply ? "sendAndReceive" : "send"). This leads to the fact that result of the sendAndReceive is not a Message, but just its payload. As expected, the mapping of this result to a JMS message fails as it is not an SI message.

    A possible fix would be to have the method name configurable in the JmxGateway (to give the user the possiblity to choose between sendAndReceive and sendAndReceiveMessage).

    One may also imagine to modify the SimpleMessagingGateway.sendAndReceive method to something like:
    public Object sendAndReceive(Object object) {
        if(object instanceof Message)
            return this.sendAndReceive(object, false);
            return this.sendAndReceive(object, true);