如何正确启动延迟路线并获取状态?(Camel v3!!!)

问题描述 投票:0回答:2
builder.from(fileOptions.toString())
                .id("rabbitMQ")
                .noAutoStartup()

Маке出发路线:

        Route route = camelContext.getRoute("rabbitMQ");
        route.warmUp();
        ServiceHelper.startService(route.getConsumer());

路由已启动,但状态为 0 (ServiceStatus.Stopped)

   if (route instanceof EventDrivenConsumerRoute)
            info.setStatus(((EventDrivenConsumerRoute) route).getStatus());
spring-boot apache-camel
2个回答
0
投票

使用

RouteController
CamelContext
API 来控制和启动路线。

https://camel.apache.org/manual/latest/route-controller.html


0
投票

你为什么不接受@Claus Ibsen的回答? 这里有更多代码来实现他所说的:

CamelContext ctx = route.getCamelContext();
// To list all routes in the context with their status
ctx.getRoutes().forEach(r->log.info("Route[RouteId: '{}', status: '{}']", r.getRouteId(), ctx.getRouteController().getRouteStatus(r.getRouteId())));

if (ctx.getRouteController().getRouteStatus(route.getRouteId())!= ServiceStatus.Started) {
    try{
        log.info(String.format("Starting Route[routeId:'%s', status:'%s'] ..",
                        route.getRouteId(), ctx.getRouteController().getRouteStatus(route.getRouteId())));

        ctx.getRouteController().startRoute(route.getRouteId());            
        while(ctx.getRouteController().getRouteStatus(route.getRouteId())!= ServiceStatus.Started) {}
        log.info("Route '{}' is now {}.", route.getRouteId(), ctx.getRouteController().getRouteStatus(route.getRouteId()));
    } catch (Exception ex) {
                log.info("Starting Route Failed", ex);
    }   
} else {
   log.info(String.format("Route[routeId:'%s' already '%s'] ..", route.getRouteId(),ctx.getRouteController().getRouteStatus(route.getRouteId())));
}
© www.soinside.com 2019 - 2024. All rights reserved.