Apache Camel:wireTap和正常关机

时间:2017-07-12 09:57:06

标签: apache-camel

当我调试我的Camel应用程序时,我意识到,路由的正常关闭会忽略由wireTap()触发的未完成任务。

如果我有这样的路线定义:

from("direct:start")
    .wireTap("bean:myWireTapBean")
    .to("mock:result");

我在myWireTapBean中设置了一个调试断点(即暂停wireTap的异步处理),然后CamelContext.stopRoute(routeId)调用产生以下日志消息:

11:36:12.352 [Thread-1] INFO  o.a.camel.spring.SpringCamelContext - Apache Camel 2.19.1 (CamelContext: camel-1) is shutting down
11:36:12.352 [Thread-1] INFO  o.a.c.impl.DefaultShutdownStrategy - Starting to graceful shutdown 1 routes (timeout 300 seconds)
11:36:12.352 [Camel (camel-1) thread #6 - ShutdownTask] INFO  o.a.c.impl.DefaultShutdownStrategy - Route: route1 shutdown complete, was consuming from: direct://myRoute
11:36:12.352 [Thread-1] INFO  o.a.c.impl.DefaultShutdownStrategy - Graceful shutdown of 1 routes completed in 0 seconds
11:36:12.478 [Thread-1] WARN  o.a.c.impl.DefaultInflightRepository - Shutting down while there are still 1 inflight exchanges.
11:36:12.478 [Thread-1] INFO  o.a.camel.spring.SpringCamelContext - Apache Camel  2.19.1 (CamelContext: camel-1) uptime 1.411 seconds
11:36:12.478 [Thread-1] INFO  o.a.camel.spring.SpringCamelContext - Apache Camel 2.19.1 (CamelContext: camel-1) is shutdown in 0.126 seconds

是否有任何方法可以阻止Camel在DefaultInflightRepository创建的wireTap中的仍有空中交换的情况下关闭? 我已经阅读了FAQ: How can I stop a route from a route,但这似乎不是这个问题的答案。

2 个答案:

答案 0 :(得分:1)

是的,如果没有路由,WireTap的当前实现不会考虑活动任务。

如果有飞行任务,我记录了一张票,以添加对推迟关闭WireTap EIP的支持:https://issues.apache.org/jira/browse/CAMEL-11539

解决方法是创建一个路由,例如direct,然后调用该路由,然后您可以调用bean,然后当您关闭Camel时,direct路由将进行机上交换因此等待它完成。

答案 1 :(得分:0)

DefaultShutdownStrategy的默认行为是完成路由关闭,因此它是默认适用于许多场景的那些事情之一,但不是全部,而你是后者。如果交换在事务中运行,它将回滚,您可能会查看从JMS队列或其他队列中获取的内容,以便您可以回滚并继续处理。

Javadocs在考虑编写自定义逻辑之前,可以使用很好的信息来配置DefaultShutdownStrategy:

DefaultShutdownStrategy