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

  • JmsGateway fails when used with in request/reply mode

    Hello,

    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:
    Code:
    <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="murex.integration.tools.vit.error.VitErrorProcessor"/>
    I get the following exception:
    Code:
    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(HeaderMappingMessageConverter.java:64)
    	at org.springframework.jms.listener.adapter.MessageListenerAdapter.buildMessage(MessageListenerAdapter.java:517)
    	at org.springframework.jms.listener.adapter.MessageListenerAdapter.handleResult(MessageListenerAdapter.java:493)
    	at org.springframework.jms.listener.adapter.MessageListenerAdapter.onMessage(MessageListenerAdapter.java:360)
    	at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:506)
    	at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:463)
    	at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:435)
    	at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:322)
    	at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:260)
    	at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:944)
    	at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:868)
    	at java.lang.Thread.run(Thread.java:619)
    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 JmsGateway.java 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:
    Code:
    public Object sendAndReceive(Object object) {
        if(object instanceof Message)
            return this.sendAndReceive(object, false);
        else
            return this.sendAndReceive(object, true);
    }
    Thanks,
    Mihai
Working...
X