暂停骆驼路线报告未暂停
Suspended camel route reports is not suspended
我正在开发消息路由器,我的部分设计是 stopping/suspending 和 starting/resuming 路由,这些路由基于控制路由中的一些文件命令。
我尝试遵循骆驼的建议来支持 suspend/resume 一条路线作为 stop/start 的替代路线。
我的恢复逻辑取决于某些路由的状态,比如我有两条路由 ABC 和 XYZ,它们不能同时处于活动状态。为了方便这一点,我的控制路由支持两个命令 SUSPEND <route id> and RESUME <route id>
。所以简而言之,如果路线 ABC 未暂停,RESUME XYZ
将不执行任何操作。
我的单元测试(使用 JMockit)顺利通过。然而,当 运行 真正的应用程序时,即使我之前暂停了路线 ABC,我也可以看到路线 XYZ 永远不会恢复。
我输入了一些日志条目,令我惊讶的是在执行 route.suspend("ABC")
显然成功地为骆驼日志条目提供路由 ABC 仍然报告为未暂停。这是代码:
LOGGER.info(r.getId() + " route supports suspension=" + r.supportsSuspension());
context.suspendRoute(r.getId());
LOGGER.info("After suspending route " + r.getId() + " the route suspended state is " + ((ServiceSupport) r).isSuspended());
下面是日志条目:
[INFO ] my.org.message.router.lifecycle.DeactivateCommand - ABC route supports suspension=true
[INFO ] org.apache.camel.impl.DefaultShutdownStrategy - Starting to graceful shutdown 1 routes (timeout 300 seconds)
[INFO ] org.apache.camel.impl.DefaultShutdownStrategy - Route: ABC suspend complete, was consuming from: Endpoint[abc://queue:SOME_QUEUE]
[INFO ] org.apache.camel.impl.DefaultShutdownStrategy - Graceful shutdown of 1 routes completed in 0 seconds
[INFO ] org.apache.camel.spring.SpringCamelContext - Route: ABC is suspended, was consuming from: Endpoint[abc://queue:SOME_QUEUE]
[INFO ] my.org.message.router.lifecycle.DeactivateCommand - After suspending route ABC the route suspended state is false
所以我的问题是:
- 这是一个错误还是我做错了
- 如果有错误可以解决或者我应该stop/start方式
- 如果是我的错,实现我所追求的目标的正确方法是什么
提前感谢您的意见
是的,这是 Apache Camel 中的一个错误,无法报告正确的状态 - 路由确实已暂停。我已经记录了一张票:https://issues.apache.org/jira/browse/CAMEL-8964
您可以使用 camelContext.getRouteStatus(routeId)
api.
获得正确的状态
我正在开发消息路由器,我的部分设计是 stopping/suspending 和 starting/resuming 路由,这些路由基于控制路由中的一些文件命令。
我尝试遵循骆驼的建议来支持 suspend/resume 一条路线作为 stop/start 的替代路线。
我的恢复逻辑取决于某些路由的状态,比如我有两条路由 ABC 和 XYZ,它们不能同时处于活动状态。为了方便这一点,我的控制路由支持两个命令 SUSPEND <route id> and RESUME <route id>
。所以简而言之,如果路线 ABC 未暂停,RESUME XYZ
将不执行任何操作。
我的单元测试(使用 JMockit)顺利通过。然而,当 运行 真正的应用程序时,即使我之前暂停了路线 ABC,我也可以看到路线 XYZ 永远不会恢复。
我输入了一些日志条目,令我惊讶的是在执行 route.suspend("ABC")
显然成功地为骆驼日志条目提供路由 ABC 仍然报告为未暂停。这是代码:
LOGGER.info(r.getId() + " route supports suspension=" + r.supportsSuspension());
context.suspendRoute(r.getId());
LOGGER.info("After suspending route " + r.getId() + " the route suspended state is " + ((ServiceSupport) r).isSuspended());
下面是日志条目:
[INFO ] my.org.message.router.lifecycle.DeactivateCommand - ABC route supports suspension=true
[INFO ] org.apache.camel.impl.DefaultShutdownStrategy - Starting to graceful shutdown 1 routes (timeout 300 seconds)
[INFO ] org.apache.camel.impl.DefaultShutdownStrategy - Route: ABC suspend complete, was consuming from: Endpoint[abc://queue:SOME_QUEUE]
[INFO ] org.apache.camel.impl.DefaultShutdownStrategy - Graceful shutdown of 1 routes completed in 0 seconds
[INFO ] org.apache.camel.spring.SpringCamelContext - Route: ABC is suspended, was consuming from: Endpoint[abc://queue:SOME_QUEUE]
[INFO ] my.org.message.router.lifecycle.DeactivateCommand - After suspending route ABC the route suspended state is false
所以我的问题是:
- 这是一个错误还是我做错了
- 如果有错误可以解决或者我应该stop/start方式
- 如果是我的错,实现我所追求的目标的正确方法是什么
提前感谢您的意见
是的,这是 Apache Camel 中的一个错误,无法报告正确的状态 - 路由确实已暂停。我已经记录了一张票:https://issues.apache.org/jira/browse/CAMEL-8964
您可以使用 camelContext.getRouteStatus(routeId)
api.