You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Damian Harvey <da...@aon.com.au> on 2010/12/14 05:28:58 UTC

JMS Exceptions

I had an error in a property file with an incorrect queue name that didn't exist. When the JMS Reply was hit a JMSException was generated "MQJMS2008: failed to open MQ queue". This is to be expected. What happens is that Camel goes into an infinite loop trying to process the message.

I was expecting my onException in the Route would handle it but it did not. I have tried to add an ExceptionListener that "is to be notified of any underlying JMS exceptions"  however I think I have the syntax wrong. Here is a simplified version of my route:

public void configure() throws Exception {
                getContext().setHandleFault(true);
                onException(JmsException.class).handled(true).to("jms:SYSTEM.DEAD.LETTER.QUEUE");
                errorHandler(deadLetterChannel("jms:SYSTEM.DEAD.LETTER.QUEUE"));

                from("jms:CBS.START?replyTo=CBS.REPLY&exceptionListener=com.aon.camel.exception.ExceptionListener")
                .process(new JmsInboundMessageProcessor())
                .recipientList(simple("${header.requestNode}")).ignoreInvalidEndpoints()
                .process(new JmsOutboundMessageProcessor());
}

Thanks,

Damian.

________________________________

This communication (and any attachments) is directed in confidence to the addressee(s) listed above, and may not otherwise be distributed, copied or used. The contents of this communication may also be subject to privilege, and all rights to that privilege are expressly claimed and not waived. If you have received this communication in error, please notify us by reply e-mail or by telephone and delete this communication (and any attachments) without making a copy.

Before opening or using attachments, you should check them for viruses and defects. We do not accept liability in connection with computer virus, data corruption, delay, interruption, unauthorised access or unauthorised amendment.

Re: JMS Exceptions

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Dec 15, 2010 at 7:35 AM, Damian Harvey <da...@aon.com.au> wrote:
> Thanks Claus. So I could get the Route starting by specifying the JMS endpoint like (note the hash):
>
> from("jms:"+getRequestQueue()+getRequestQueueOps()+"&exceptionListener=#jmsExceptionListener")
>
> So that when Camel starts I can see the following in the logs:
>
> Route: JmsRouter started and consuming from: Endpoint[jms://CBS.ASYNC?exceptionListener=%23jmsExceptionListener&replyTo=CBS.REPLY.NSYNC]
>
> However when I cause the exception with the Queue missing, this ExceptionListener is never hit and Camel goes into the infinite loop with the MQJMS2008 error.
>

We could probably add some option to camel-jms, to let it test on
startup that the fixed reply to queue exists and that it can connect
to it. Something like the testConnectionOnStartup option.



The exception lister is whatever Spring JMS decides to report. So it
may not be able to detect and report this. Also mind that when sending
a message you can do this asynchronously or synchronously (this is
vendor specific). The latter most often allows the client to be aware
of the error as a JmsException will be thrown back when sending.


> I can't see an example of ExceptionListener. The JMS tests that have exception handling (eg. JMSValidatorTest, ActiveMQ HighVolume) use doTry and doCatch. However these won't work in this case as the doTry would have to be outside the first "from" (which is the JMS endpoint).
>
> Is there a better way to handle these types of "missing resource" exceptions? Why does Camel go into this loop? I assume it is because it is rolling the message back to the source queue and trying again. This being the case how can I prevent this from happening?
>

Yeah it could be a redelivery performed by your JMS broker. The JMS
broker has some settings so you can configure how it should handle
redeliveries. For example you should be able to say: after X failed
redeliveries then move the message to this dead letter queue.

For example for AMQ
http://activemq.apache.org/redelivery-policy.html
http://activemq.apache.org/message-redelivery-and-dlq-handling.html



> Thanks,
>
> Damian.
>
>
>
> -----Original Message-----
> From: Claus Ibsen [mailto:claus.ibsen@gmail.com]
> Sent: Tuesday, 14 December 2010 6:04 PM
> To: users@camel.apache.org
> Subject: Re: JMS Exceptions
>
> A good idea is to check the unit test of camel-jms and search for exceptionListener to see how to use this option.
>
> You need to refer to a bean id which it will lookup in the spring xml file.
>
> exceptionListener=foo
>
> <bean id="foo" class="..."/>
>
>
> On Tue, Dec 14, 2010 at 5:28 AM, Damian Harvey <da...@aon.com.au> wrote:
>> I had an error in a property file with an incorrect queue name that didn't exist. When the JMS Reply was hit a JMSException was generated "MQJMS2008: failed to open MQ queue". This is to be expected. What happens is that Camel goes into an infinite loop trying to process the message.
>>
>> I was expecting my onException in the Route would handle it but it did not. I have tried to add an ExceptionListener that "is to be notified of any underlying JMS exceptions"  however I think I have the syntax wrong. Here is a simplified version of my route:
>>
>> public void configure() throws Exception {
>>                getContext().setHandleFault(true);
>>
>> onException(JmsException.class).handled(true).to("jms:SYSTEM.DEAD.LETT
>> ER.QUEUE");
>>
>> errorHandler(deadLetterChannel("jms:SYSTEM.DEAD.LETTER.QUEUE"));
>>
>>
>> from("jms:CBS.START?replyTo=CBS.REPLY&exceptionListener=com.aon.camel.
>> exception.ExceptionListener")
>>                .process(new JmsInboundMessageProcessor())
>>
>> .recipientList(simple("${header.requestNode}")).ignoreInvalidEndpoints
>> ()
>>                .process(new JmsOutboundMessageProcessor()); }
>>
>> Thanks,
>>
>> Damian.
>>
>> ________________________________
>>
>> This communication (and any attachments) is directed in confidence to the addressee(s) listed above, and may not otherwise be distributed, copied or used. The contents of this communication may also be subject to privilege, and all rights to that privilege are expressly claimed and not waived. If you have received this communication in error, please notify us by reply e-mail or by telephone and delete this communication (and any attachments) without making a copy.
>>
>> Before opening or using attachments, you should check them for viruses and defects. We do not accept liability in connection with computer virus, data corruption, delay, interruption, unauthorised access or unauthorised amendment.
>>
>
>
>
> --
> Claus Ibsen
> -----------------
> FuseSource
> Email: cibsen@fusesource.com
> Web: http://fusesource.com
> Twitter: davsclaus
> Blog: http://davsclaus.blogspot.com/
> Author of Camel in Action: http://www.manning.com/ibsen/
>
>
> This communication (and any attachments) is directed in confidence to the addressee(s) listed above, and may not otherwise be distributed, copied or used. The contents of this communication may also be subject to privilege, and all rights to that privilege are expressly claimed and not waived. If you have received this communication in error, please notify us by reply e-mail or by telephone and delete this communication (and any attachments) without making a copy.
>
> Before opening or using attachments, you should check them for viruses and defects. We do not accept liability in connection with computer virus, data corruption, delay, interruption, unauthorised access or unauthorised amendment.
>
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

RE: JMS Exceptions

Posted by Damian Harvey <da...@aon.com.au>.
Thanks Claus. So I could get the Route starting by specifying the JMS endpoint like (note the hash):

from("jms:"+getRequestQueue()+getRequestQueueOps()+"&exceptionListener=#jmsExceptionListener")

So that when Camel starts I can see the following in the logs:

Route: JmsRouter started and consuming from: Endpoint[jms://CBS.ASYNC?exceptionListener=%23jmsExceptionListener&replyTo=CBS.REPLY.NSYNC]

However when I cause the exception with the Queue missing, this ExceptionListener is never hit and Camel goes into the infinite loop with the MQJMS2008 error.

I can't see an example of ExceptionListener. The JMS tests that have exception handling (eg. JMSValidatorTest, ActiveMQ HighVolume) use doTry and doCatch. However these won't work in this case as the doTry would have to be outside the first "from" (which is the JMS endpoint).

Is there a better way to handle these types of "missing resource" exceptions? Why does Camel go into this loop? I assume it is because it is rolling the message back to the source queue and trying again. This being the case how can I prevent this from happening?

Thanks,

Damian.



-----Original Message-----
From: Claus Ibsen [mailto:claus.ibsen@gmail.com]
Sent: Tuesday, 14 December 2010 6:04 PM
To: users@camel.apache.org
Subject: Re: JMS Exceptions

A good idea is to check the unit test of camel-jms and search for exceptionListener to see how to use this option.

You need to refer to a bean id which it will lookup in the spring xml file.

exceptionListener=foo

<bean id="foo" class="..."/>


On Tue, Dec 14, 2010 at 5:28 AM, Damian Harvey <da...@aon.com.au> wrote:
> I had an error in a property file with an incorrect queue name that didn't exist. When the JMS Reply was hit a JMSException was generated "MQJMS2008: failed to open MQ queue". This is to be expected. What happens is that Camel goes into an infinite loop trying to process the message.
>
> I was expecting my onException in the Route would handle it but it did not. I have tried to add an ExceptionListener that "is to be notified of any underlying JMS exceptions"  however I think I have the syntax wrong. Here is a simplified version of my route:
>
> public void configure() throws Exception {
>                getContext().setHandleFault(true);
>
> onException(JmsException.class).handled(true).to("jms:SYSTEM.DEAD.LETT
> ER.QUEUE");
>
> errorHandler(deadLetterChannel("jms:SYSTEM.DEAD.LETTER.QUEUE"));
>
>
> from("jms:CBS.START?replyTo=CBS.REPLY&exceptionListener=com.aon.camel.
> exception.ExceptionListener")
>                .process(new JmsInboundMessageProcessor())
>
> .recipientList(simple("${header.requestNode}")).ignoreInvalidEndpoints
> ()
>                .process(new JmsOutboundMessageProcessor()); }
>
> Thanks,
>
> Damian.
>
> ________________________________
>
> This communication (and any attachments) is directed in confidence to the addressee(s) listed above, and may not otherwise be distributed, copied or used. The contents of this communication may also be subject to privilege, and all rights to that privilege are expressly claimed and not waived. If you have received this communication in error, please notify us by reply e-mail or by telephone and delete this communication (and any attachments) without making a copy.
>
> Before opening or using attachments, you should check them for viruses and defects. We do not accept liability in connection with computer virus, data corruption, delay, interruption, unauthorised access or unauthorised amendment.
>



--
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/


This communication (and any attachments) is directed in confidence to the addressee(s) listed above, and may not otherwise be distributed, copied or used. The contents of this communication may also be subject to privilege, and all rights to that privilege are expressly claimed and not waived. If you have received this communication in error, please notify us by reply e-mail or by telephone and delete this communication (and any attachments) without making a copy.

Before opening or using attachments, you should check them for viruses and defects. We do not accept liability in connection with computer virus, data corruption, delay, interruption, unauthorised access or unauthorised amendment.


Re: JMS Exceptions

Posted by Claus Ibsen <cl...@gmail.com>.
A good idea is to check the unit test of camel-jms and search for
exceptionListener to see how to use this option.

You need to refer to a bean id which it will lookup in the spring xml file.

exceptionListener=foo

<bean id="foo" class="..."/>


On Tue, Dec 14, 2010 at 5:28 AM, Damian Harvey <da...@aon.com.au> wrote:
> I had an error in a property file with an incorrect queue name that didn't exist. When the JMS Reply was hit a JMSException was generated "MQJMS2008: failed to open MQ queue". This is to be expected. What happens is that Camel goes into an infinite loop trying to process the message.
>
> I was expecting my onException in the Route would handle it but it did not. I have tried to add an ExceptionListener that "is to be notified of any underlying JMS exceptions"  however I think I have the syntax wrong. Here is a simplified version of my route:
>
> public void configure() throws Exception {
>                getContext().setHandleFault(true);
>                onException(JmsException.class).handled(true).to("jms:SYSTEM.DEAD.LETTER.QUEUE");
>                errorHandler(deadLetterChannel("jms:SYSTEM.DEAD.LETTER.QUEUE"));
>
>                from("jms:CBS.START?replyTo=CBS.REPLY&exceptionListener=com.aon.camel.exception.ExceptionListener")
>                .process(new JmsInboundMessageProcessor())
>                .recipientList(simple("${header.requestNode}")).ignoreInvalidEndpoints()
>                .process(new JmsOutboundMessageProcessor());
> }
>
> Thanks,
>
> Damian.
>
> ________________________________
>
> This communication (and any attachments) is directed in confidence to the addressee(s) listed above, and may not otherwise be distributed, copied or used. The contents of this communication may also be subject to privilege, and all rights to that privilege are expressly claimed and not waived. If you have received this communication in error, please notify us by reply e-mail or by telephone and delete this communication (and any attachments) without making a copy.
>
> Before opening or using attachments, you should check them for viruses and defects. We do not accept liability in connection with computer virus, data corruption, delay, interruption, unauthorised access or unauthorised amendment.
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/