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());
使用
RouteController
的 CamelContext
API 来控制和启动路线。
https://camel.apache.org/manual/latest/route-controller.html
你为什么不接受@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())));
}