[英]Stopping a Camel route from outside the route
我們有一個在 Karaf 2.4.3 和 Camel 2.15.3 上運行的數據處理應用程序。
在這個應用程序中,我們有一堆導入數據的路由。 我們有一個管理視圖,其中列出了這些路由以及每個路由的起點。 這些路由不直接導入數據,而是調用其他路由(其中一些在其他包中,通過direct-vm
調用),有時直接調用,有時在拆分器中調用。
有沒有辦法也完全停止路由/從而停止進一步處理整個交換?
當簡單地使用stopRoute
函數時:
route.getRouteContext().getCamelContext().stopRoute(route.getId());
我最終收到一條成功消息, Graceful shutdown of 1 routes completed in 10 seconds
由的正常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);
}
有沒有辦法完全阻止從路由外部處理交換?
可以換嗎? 我使用exchange.setProperty(Exchange.ROUTE_STOP, true);
路線停止流動,不去下一條路線。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.