【发布时间】:2014-02-07 20:14:28
【问题描述】:
我正在使用 Camel 读取 JMS 队列并放置在 SEDA 队列中,然后通过单独的路由读取并进行处理。有时,如果我的应用程序出现问题,我的 SEDA 队列会填满,我会得到:
java.lang.IllegalStateException: Queue full
这是有道理的。我想捕获这个异常,所以我可以停止订阅 JMS 的路由(阻止更多消息进入),但我似乎无法捕获它。
这是我的路线(简化):
from("{{jms.loader.in}}")
.setExchangePattern(ExchangePattern.InOnly)
.routeId(this.getClass().getSimpleName())
.to("seda://JmsFetchRoute_incoming);
我试图将它包围在一个 doTry - doCatch 中,但没有捕获到异常:
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();
似乎无论我在“doCatch”块中尝试做什么,它都不会达到这一点。那么如何将“调用”包装到 SEDA 队列,以便捕获 Queue Full 异常?
EDIT1
根据 hveiga 的回答,我还尝试使用“onException”创建一个 ErrorHandlingRoute 并将其添加到我的上下文中,但这也没有成功:
@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();
}
我也将它添加到我的 fetch 路线中,但仍然没有拿起它:
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
根据this post onException 不能在单独的RouteBuilder中定义...
EDIT3
仍然没有运气从同一个路由构建器中捕获异常,所以我给了我的“onException”路由一个名称,但是当在 JMX 中检查时这个名称不在 Camel 的“路由”部分中?我需要打开配置以启用“onException”路由吗?
【问题讨论】:
标签: java apache-camel