从路线外停止骆驼路线

时间:2017-01-16 07:48:36

标签: java apache-camel osgi apache-karaf blueprint

我们有一个数据处理应用程序,使用Camel 2.15.3在Karaf 2.4.3上运行。

在这个应用程序中,我们有一堆导入数据的路由。我们有一个管理视图,列出了这些路由以及每条路由的起始位置。这些路由不直接导入数据,而是调用其他路由(其中一些路由在其他捆绑中,通过direct-vm调用),有时直接和有时在分路器中。

有没有办法完全停止路线/因此阻止整个交易所被进一步处理?

简单地使用这样的stopRoute函数:

route.getRouteContext().getCamelContext().stopRoute(route.getId());

我最终获得了Graceful shutdown of 1 routes completed in 10 seconds的成功消息 - 交换仍在处理中......

所以我尝试通过设置stop属性来模仿StopProcessor的行为,但这也没有帮助:

public void stopRoute(Route route) {
    try {
        Collection<InflightExchange> browse = route.getRouteContext().getCamelContext().getInflightRepository()
                .browse();
        for (InflightExchange inflightExchange : browse) {
            String exchangeRouteId = inflightExchange.getRouteId();
            if ((exchangeRouteId != null) && exchangeRouteId.equals(route.getId())) {
                this.stopExchange(inflightExchange.getExchange());
            }
        }
    } catch (Exception e) {
        Notification.show("Error while trying to stop route", Type.ERROR_MESSAGE);
        LOGGER.error(e, e);
    }
}

public void stopExchange(Exchange exchange) throws Exception {
    AsyncProcessorHelper.process(new AsyncProcessor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            AsyncProcessorHelper.process(this, exchange);
        }

        @Override
        public boolean process(Exchange exchange, AsyncCallback callback) {
            exchange.setProperty(Exchange.ROUTE_STOP, Boolean.TRUE);
            callback.done(true);
            return true;
        }
    }, exchange);
}

有没有办法完全阻止交换从路线外部处理?

1 个答案:

答案 0 :(得分:0)

你能换个交易吗? 我用exchange.setProperty(Exchange.ROUTE_STOP, true); 路线停止流程,不会进入下一条路线。