Announcement Announcement Module
No announcement yet.
Required Response for Gateway Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Required Response for Gateway

    I am a newbie at spring integration. I had thought that if i define my method as void, then it knows not to wait for a response.
    So i defined my gateway as follows:
    public interface JmsGateway

    public void sendASynchronously(@Headers Map<String,Object> headers, @Payload String message);

    Yet, i get the following error: MessageTimeoutException: failed to receive JMS response within timeout of: 5000ms

    My xml is as follows:
    <si:channel id="targetProvisionChannel" />
    <jms:outbound-gateway id="targetProvisionGateway" request-channel="targetProvisionChannel" connection-factory="amqConnectionFactory"
    request-destination="target_provision" />
    <si:gateway id="gateway" service-interface="jms.JmsGateway"
    default-request-channel="targetProvisionChannel" />

    Is there something obvious I am missing here?

  • #2
    It still runs on your thread by default; see this thread, that shows a number of mechanisms to get the behavior you want...


    • #3
      Thanks, i couldnt find information that clarfied for me how to use the Executor Channel but after i posted i found something that seems to work for me so i figured i would post it here. The <jms:outbound-channel-adapter...> allows for fire and forget while the jms:outbound-gateway does not. So, i configured both, where each uses a different request channel and when i want the async one, i send to the outbound-channel-adapter and when i want the synchronous i send to the gateway. And they can even work on the same JMS queue!

      So the xml looks like this:

      <si:channel id="ProvisionChannelSync"/>
      <si:channel id="ProvisionChannelAsync"/>

      <jms:outbound-gateway id="ProvisionGateway" request-channel="ProvisionChannelSync"

      <jms:outbound-channel-adapter channel="ProvisionChannelAsync" connection-factory="amqConnectionFactory"/>

      Then in my interface i use annotations to point the async and synch to the different channels

      @Gateway(requestChannel = "ProvisionChannelSync")
      @Gateway(requestChannel = "ProvisionChannelASync")



      • #4
        Well, that is the correct thing to do if you are not expecting a response; otherwise you'd tie up a thread waiting for a response that never arrives.

        For future reference, to turn a <channel/> into an Executor channel; simply add a task-executor attribute, normally referencing a <task:executor/> bean.

        Then, when the message is sent to the channel, it is handed off to a thread from the Executor and the calling thread returns.


        • #5
          I just wanted to add... it's seems that you might be confusing the request/reply (gateway) vs. one-way (channel-adapter) behavior with sync vs. async, respectively. In reality, the JMS send is always async (in that the Message is sent from Producer to Broker and then send() returns - rather than waiting on the Consumer to receive it), but our outbound-gateway is intended for use-cases where you *expect* a response on the Destination represented by the JMS ReplyTo property. Therefore, the gateway does an async JMS send but then waits for a reply. If no reply occurs within the allotted timeout, an Exception is thrown. If you are not expecting a reply at all, then you should not use our outbound-gateway; use the outbound-channel-adapter instead.

          Hope that helps.