I am using Camel to read off a JMS queue and place on a SEDA queue, which then gets read by a separate route and processed. Sometimes if something goes wrong in my application my SEDA queue fills up, and I get:
java.lang.IllegalStateException: Queue full
This makes sense. I want to catch this exception, so I can stop the route that is subscribing to JMS (to stop any more messages from coming in), but I don't seem to be able to catch it.
This is my route (simplified):
from("{{jms.loader.in}}")
.setExchangePattern(ExchangePattern.InOnly)
.routeId(this.getClass().getSimpleName())
.to("seda://JmsFetchRoute_incoming);
I tried to surround it in a doTry - doCatch, but the exception was not caught:
from("{{jms.loader.in}}")
.setExchangePattern(ExchangePattern.InOnly)
.routeId(this.getClass().getSimpleName())
.doTry()
.to("seda://JmsFetchRoute_incoming)
.doCatch(Exception.class)
.log(LoggingLevel.ERROR, "Your queue is full!")
.end();
It seems no matter what I try and do in the 'doCatch' block, it never reaches this point. So how can I wrap the 'call' to the SEDA queue such that I can catch the Queue Full exception?
EDIT1
As per hveiga's answer, I also tried creating an ErrorHandlingRoute with 'onException' and adding that to my context, but that also didn't pick it up:
@Override
public void configure() throws Exception {
onException(IllegalStateException.class)
.handled(true)
.log(LoggingLevel.ERROR, "Exception route stopping topic route, SEDA queue full")
.to("controlbus:route?routeId=JmsFetchRoute&action=stop")
.end();
}
I also added it to my fetch route, still didn't pick it up:
from("{{jms.loader.in}}")
.setExchangePattern(ExchangePattern.InOnly)
.routeId(this.getClass().getSimpleName())
.onException(IllegalStateException.class)
.handled(true)
.log(LoggingLevel.ERROR, "Topic consumer stopping route, SEDA queue full : " + this.getClass().getSimpleName())
.to("controlbus:route?routeId="+this.getClass().getSimpleName()+"&action=stop")
.end()
.to("seda://JmsFetchRoute_incoming);
EDIT2
According this post the onException can not be defined in a separate RouteBuilder...
EDIT3
Still no luck getting an exception caught from inside the same routebuilder, so I gave my 'onException' route a name but this name is not in the 'routes' part of Camel when checked in JMX?? Is there a config I need to turn on to enable 'onException' routes?