2 Replies Latest reply on Jul 25, 2011 11:46 AM by jamie3_james.archibald

    requestBody timeout when using activemq:queue

    jamie3_james.archibald

      I have a simple client that sends a text message to a database listening on the queue "Request":

       

      String response = template.requestBody("activemq:queue:Request", "test", String.class);

       

      When the consumer database throws an exception (eg. SQLException) I would expect the client to receive the exception wrapped inside RuntimeCamelException. This, however, doesn't seem to work. Instead my client receives a JMS Timeout exception.

       

      On the consumer database I can see that camel is wrapping the exception (as per the documentation), but my client never gets the exception.

       

       

      [ad #0 - JmsConsumer[dbRequest]] JmsMessageListenerContainer    WARN  Execution of JMS message listener failed, and no ErrorHandler has been set.

      org.apache.camel.RuntimeCamelException: java.lang.RuntimeException: newDevice failed: ERROR: duplicate key value violates unique constraint "devices_pkey"

        Detail: Key (kdeviceguid)=(8032a949-2b61-458e-8909-fced3a494222) already exists.

           at org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1139)[camel-core-2.7.2.jar:2.7.2]

           at org.apache.camel.component.jms.EndpointMessageListener.onMessage(EndpointMessageListener.java:115)[camel-jms-2.7.0.jar:2.7.0]

           at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:560)[spring-jms-3.0.5.RELEASE.jar:3.0.5.RELEASE]

           at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:498)[spring-jms-3.0.5.RELEASE.jar:3.0.5.RELEASE]

           at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:467)[spring-jms-3.0.5.RELEASE.jar:3.0.5.RELEASE]

           at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:325)[spring-jms-3.0.5.RELEASE.jar:3.0.5.RELEASE]

           at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:263)[spring-jms-3.0.5.RELEASE.jar:3.0.5.RELEASE]

           at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1058)[spring-jms-3.0.5.RELEASE.jar:3.0.5.RELEASE]

           at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1050)[spring-jms-3.0.5.RELEASE.jar:3.0.5.RELEASE]

           at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:947)[spring-jms-3.0.5.RELEASE.jar:3.0.5.RELEASE]

           at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)[:1.6.0_26]

           at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)[:1.6.0_26]

           at java.lang.Thread.run(Thread.java:662)[:1.6.0_26]

        • 1. Re: requestBody timeout when using activemq:queue
          njiang

          Hi,

           

          You need to set the "transferException" option of the activemq-camel component to be true, and make sure the exception can be serialized.

           

          Willem

          • 2. Re: requestBody timeout when using activemq:queue
            jamie3_james.archibald

            Sorry, I should have been more descriptive.

             

            I don't want to receive the exception object from the consumer. Instead I want ActiveMQ to send me (eg. the client) an exception when the consumer (eg. the server) throws an exception in the route.

             

            Currently the consumer is generating an exception, I can see camel wrapping the exception in the RuntimeCamelException class, however my client never receives any exception, but instead 20 seconds later gets a Timeout exception. I want the client to receive the exception immediately.

             

            Here is a simple unit test:

             

                 @Test

                 public void sendMessageExpectException() {

                      try{

                                String retVal = template.requestBody("activemq:queue:Foo", "Bar", String.class);

                                  fail("the server should have thrown an exception")

                      }catch(Exception ex){

                           if (ex.getCause().getClass() == ExchangeTimedOutException.class) {

                                fail("Timeout occurred");

                           }

                                    // yahoo!

                      }

                 }

             

            Edited by: jamie3 on Jul 25, 2011 3:01 PM

             

            Edited by: jamie3 on Jul 25, 2011 3:45 PM