暂停和恢复骆驼路线

时间:2014-07-28 12:26:54

标签: apache-camel fuseesb jbossfuse

您好我正在使用驼峰的JMS消费者路由,我的要求是在某些事件中停止/暂停该路由(基于某个字段值),然后使用调度程序恢复该路由。 为此我创建了两条路线,一条是我原来的jms消费者路线,另一条是调度路线,恢复了jms消费者路线,虽然我能够暂停路线,但第二条路线没有恢复暂停的路线而且显示状态一开始。

以下是我的两条路线

原始消费者路线

from("activeMQ:demo.audit.event1?testConnectionOnStartup=true&acknowledgementModeName=CLIENT_ACKNOWLEDGE")
    .routeId("javadslconsumer")
    .log("before stopping==="+new Date().toString())
    .process(new Processor() {
          @Override
          public void process(final Exchange exchange) throws Exception {
              try {
                  Route route = exchange.getContext().getRoute("javadslconsumer");
                  System.out.println("route.supportsSuspension()"+route.supportsSuspension());
                  exchange.getContext().suspendRoute("javadslconsumer",1l,TimeUnit.SECONDS);
                  // create another helper route, using which we can start or resume this route based 
                  // on the current life cycle phase of this route.    
              } catch (Exception e) {
                  // ignore
                  e.printStackTrace();
                }
            }
        })
    .log("after stopping logs==="+new Date().toString())
    .unmarshal(dataFormat)
    .beanRef("auditProcessor", "getErrorAuditDTO")
    .beanRef("auditProcessor", "processCreateAudit");   

调度程序路径

from("timer:dlqscheduler?period=6000&fixedRate=true")
.process(new Processor(){
    @Override
    public void process(Exchange exchange) throws Exception {
        System.out.println("timer process started");
        try {
            exchange.getContext().resumeRoute("javadslconsumer");
            //exchange.getContext().startRoute("javadslconsumer");
        } catch (Exception e) {
            System.out.println("-----d-d-d-d-"+e.getMessage());
        }
        ServiceStatus serviceStatus  = getContext().getRouteStatus("javadslconsumer");
        System.out.println("serviceStatus.isStopped()"+serviceStatus.isStopped()); // showing false instead of true
        System.out.println("serviceStatus.isSuspended()"+serviceStatus.isSuspended()); // showing false instead of true
        System.out.println("serviceStatus"+serviceStatus);// showing started
    }       
})
.log("after resuming the route javadslconsumer");

请帮助我如何实现上述方案。

1 个答案:

答案 0 :(得分:3)

你需要给它更多的时间超过1秒。这是一个后备超时,所以如果暂停不能在1秒内发生,那么让路线运行。例如,阅读您使用的API的javadoc文档,您可以看到该信息。

另外还有一个controlbus组件,因此您只需向端点发送一条消息即可暂停/恢复路由。