[英]Apache Camel quartz2 cron misfire
I am using Apache Camel with spring boot and a camel-config.xml file. 我正在将Apache Camel与Spring Boot和camel-config.xml文件一起使用。 I created a simple route that runs every second and runs a class method: 我创建了一条简单的路由,该路由每秒钟运行一次并运行一个类方法:
<camelContext xmlns="http://camel.apache.org/schema/spring" id="myContext" trace="true" streamCache="true" useMDCLogging="true">
<route id="testCron">
<from uri="quartz2://TestCron?cron=0/1 * * * * ?" />
<to uri="bean:folder.MyClass?method=test" />
</route>
</camelContext>
The class simply has a counter int that is incremented and displayed: 该类仅具有一个递增和显示的计数器int:
package folder;
public class MyClass {
private static int count = 0;
public static void test(Exchange exchange) throws Exception {
count = count + 1;
System.out.println(count);
}
}
I have another piece of code (irrelevant to show) that can start and stop the above route. 我还有另一段代码(与显示无关)可以启动和停止上述路线。 The issue I am having is when stopping the route, waiting 5 seconds and start it back. 我遇到的问题是停止路线,等待5秒钟并重新启动路线。
Instead of continuing where it left the count, it catches up every iteration that it did not do while the route was stopped. 它没有继续它离开计数的地方,而是追赶了路线停止时未执行的每次迭代。
I've read a lot trying to solve that. 我已经读过很多文章试图解决这个问题。 What I learnt was the bellow: 我学到的是波纹管:
What I tried without luck: 我没有运气的尝试:
I am completely out of options :x Would appreciate any help :) 我完全没有选择余地:x将不胜感激:)
I was not able to find a way to modify the misfire instructions but I found a workaround. 我找不到修改失火指令的方法,但找到了解决方法。
Instead of stopping the route with context.stopRoute(routeId), I am now stopping the endpoint : 我现在不再使用context.stopRoute(routeId)停止路由,而是停止端点:
public static void stopRoute(Exchange exchange) throws Exception {
String beanId = (String) exchange.getIn().getHeader("beanId");
String routeId = (String) exchange.getIn().getHeader("routeId");
SpringCamelContext context = (SpringCamelContext) exchange.getContext().getRegistry().lookupByName(beanId);
for (Route route : context.getRoutes()) {
if (route.getId().equals(routeId)) {
route.getEndpoint().stop();
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.