Announcement Announcement Module
Collapse
No announcement yet.
Outbound Gateway Dilemma Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Outbound Gateway Dilemma

    I am using a using an outbound gateway in a request/reply scenario. I am able to send one request and receive the reply. Efforts to send a second request results in a MessageTimeoutException.

    The server, using an inbound-gateway, chain and service activator appears to work fine. In fact, the second reply is on the message queue waiting to be read by the client but for some reason the inbound-gateway isn't picking it up.

    I use a ChannelResolver to obtain a MessageChannel which I then use to send a message.

    The fact that I am able to consistently receive the first reply would seem to suggest that the wiring of the components is basically correct.

    Should a be able to use the same message channel to send multiple messages? Is there some setting that is necessary for this scenario to work?

  • #2
    Are you talking about JMS gateways? Can you provide some configuration excerpts?

    Comment


    • #3
      Hi Mark! Yes, I'm using JMS. Here are the configuration elements:

      Server side (inbound-gateway):

      Code:
      <beans:bean id="manager" class="business.Manager"/>
      
      <jms:inbound-gateway id="jmsin" request-destination="some.queue" request-channel="jmsinputchannel"/>
      
      <chain input-channel="jmsinputchannel">
           <transformer id="xml-to-object" ref="marshaller" method="unmarshal" />
           <service-activator ref="manager" method="process" />
           <transformer id="object-to-xml" ref="marshaller" method="marshal" />
      </chain>
      Client side (outbound-gateway):
      Code:
      <gateway id="someService" service-interface="services.SomeService" 
                        default-request-channel="someServiceRequestChannel" 
                        default-reply-channel="someServiceReplyChannel"/>
      
      <channel id="someServiceRequestChannel"/>
      
      <jms:outbound-gateway request-channel="someServiceRequestChannel"
                           request-destination="some.queue"
                           reply-destination="some.other.queue" 
                           reply-channel="someServiceReplyChannel"/>
      
      <channel id="someServiceReplyChannel"/>
      Thanks!
      Edit/Delete Message

      Comment


      • #4
        The problem is in your configuration. You are creating a conflict when pointing to the same channel while defining default-reply-channel on Gateway and reply-channel on OutboundMessageGateway.
        Basically your two Gateway are listening on the same channel.

        Modify your server configuration as follows:
        Code:
        <gateway id="someService" service-interface="services.SomeService" 
                          default-request-channel="someServiceRequestChannel" 
                          default-reply-channel="someServiceReplyChannel"/>
        
        <channel id="someServiceRequestChannel"/>
        
        <jms:outbound-gateway request-channel="someServiceRequestChannel"
                             request-destination="some.queue"
                             reply-destination="some.other.queue"/>
        
        <channel id="someServiceReplyChannel"/>
        Note how JmsOutboundGateway configuration does not have an reply-channel anymore. A temporary channel will be created from which the message will be picked up by the main Gateway.

        Let me know how.

        Comment


        • #5
          Hi Oleg,

          Thanks for your reply. I did what you suggested and, unfortunately, got the same results. I originally did not have the gateway but only the jms:outbound-gateway and got the timeout every time I made a second request.

          The client code uses the service interface to call the remote service twice. If I remove all of the business logic on the server and simply have the server echo the message the exception still occurs on the second request/response cycle.

          If I code the client to send only one message and terminate no exception is thrown. If I run the client multiple times in succession sending only one message each time, leaving the server on the entire time, there are no problems. As soon as I have the client send two (or more) messages during one run, the exception occurs. I'm thinking that the client is not releasing some resource but don't have an idea of what that might be. It seems that the service side is working fine.
          Last edited by w2m; Jun 15th, 2010, 05:43 PM.

          Comment


          • #6
            Can you provide the revised configuration?

            Comment


            • #7
              Indeed, since your previous configuration was generating slightly different error

              Comment


              • #8
                The server configuration did not change at all. The client configuration changed per Oleg's suggestion. The error message has always been the same (see below):

                Client Configuration
                Code:
                	<gateway id="someService" service-interface="services.SomeService" 
                			   default-request-channel="someServiceRequestChannel" 
                			   default-reply-channel="someServiceReplyChannel"/>
                
                	<channel id="someServiceRequestChannel"/>
                
                	<jms:outbound-gateway request-channel="someServiceRequestChannel"
                			  request-destination="some.queue"
                			  reply-destination="some.other.queue"/>
                	
                	<channel id="someServiceReplyChannel"/>

                Stack Trace:
                Code:
                Exception in thread "main" org.springframework.integration.message.MessageTimeoutException: failed to receive JMS response within timeout of: 5000ms
                	at org.springframework.integration.jms.JmsOutboundGateway.handleRequestMessage(JmsOutboundGateway.java:305)
                	at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:91)
                	at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:63)
                	at org.springframework.integration.endpoint.HandlerInvocationChain.handleMessage(HandlerInvocationChain.java:58)
                	at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:103)
                	at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:90)
                	at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:43)
                	at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:176)
                	at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:149)
                	at org.springframework.integration.channel.MessageChannelTemplate.doSend(MessageChannelTemplate.java:224)
                	at org.springframework.integration.channel.MessageChannelTemplate.doSendAndReceive(MessageChannelTemplate.java:251)
                	at org.springframework.integration.channel.MessageChannelTemplate.sendAndReceive(MessageChannelTemplate.java:216)
                	at org.springframework.integration.gateway.AbstractMessagingGateway.sendAndReceiveMessage(AbstractMessagingGateway.java:174)
                	at org.springframework.integration.gateway.AbstractMessagingGateway.sendAndReceive(AbstractMessagingGateway.java:157)
                	at org.springframework.integration.gateway.AbstractMessagingGateway.sendAndReceive(AbstractMessagingGateway.java:148)
                	at org.springframework.integration.gateway.GatewayProxyFactoryBean.invokeGatewayMethod(GatewayProxyFactoryBean.java:213)
                	at org.springframework.integration.gateway.GatewayProxyFactoryBean.invoke(GatewayProxyFactoryBean.java:182)
                	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
                	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
                Last edited by w2m; Jun 15th, 2010, 07:08 PM.

                Comment


                • #9
                  What messaging system are you using? The error message simply states that JMSGateway was waiting for the reply to be sent and it was not delivered in 5 seconds so it timed out. Try to increase timeout via reply-timeout attribute.

                  I can give you working configuration that I was using via ActiveMQ Embedded Broker

                  Comment


                  • #10
                    I am using ActiveMQ.

                    I increased the timeout to 15 seconds and set the server to only echo the request message (no business processing). The same timeout exception occurs.

                    With the original client configuration, I could see the second reply message on the queue even though the client wasn't reading it and timing out.

                    If a client only sends one message, I can use multiple clients and they all get their reply. However, if one client sends two messages, the exception occurs.

                    Comment


                    • #11
                      Can you try removing the "default-reply-channel" from the <gateway> element (so it relies on a default, anonymous reply channel)?

                      Comment


                      • #12
                        Ok, I was able to replicated it . Sorry before i was only sending 1 message, but you explicitly said you have problem when its more then one.

                        Let me figure out whats going on.

                        Comment


                        • #13
                          I removed the "default-reply-channel" but got the same result.

                          Comment


                          • #14
                            Ok, here is what's going on.
                            ActiveMQ creates a working directory usually at the root of your project:/activemq-data/localhost... where it caches your configuration and its state.
                            Apparently you have some corrupted data (e.g., messages, destination configuration etc.) in it. Luckily while playing with it i was able to accumulate corrupted data there as well which allowed me to replicate the problem. By deleting this directory everything should work fine with latest configuration.
                            I am also attaching my test so you can take a look.
                            Let me know.

                            Comment


                            • #15
                              Hi Oleg,
                              I did a search for activemq-data on both the client and server machines and found no matches.

                              If a corrupted directory is the problem, then the Spring Integration code that I have should work with some other JMS implementation besides ActiveMQ. Do you have a suggestion for an open source alternative?

                              Also, why would the code work only when one message is being sent but not with two or more? It seems to me that if something is corrupted, that the program wouldn't work at all.

                              Comment

                              Working...
                              X