标签:camel route routebuilder routedefinition
Camel添加路由一般情况下是调用CamelContext的addRoutes(RoutesBuilder builder)方法实现的,下面我们看看该方法是如何实现路由的添加的:
public void addRoutes(RoutesBuilder builder) throws Exception { //调用RouteBuilder的addRoutesToCamelContext方法,并将CamelContext作为参数传递进去 builder.addRoutesToCamelContext(this); }
public void addRoutesToCamelContext(CamelContext context) throws Exception { configureRoutes((ModelCamelContext)context); populateRoutes(); }
public RoutesDefinition configureRoutes(ModelCamelContext context) throws Exception { setContext(context); checkInitialized(); routeCollection.setCamelContext(context); return routeCollection; }
protected void checkInitialized() throws Exception { if (initialized.compareAndSet(false, true)) { ModelCamelContext camelContext = getContext(); if (camelContext.getErrorHandlerBuilder() != null) { setErrorHandlerBuilder(camelContext.getErrorHandlerBuilder()); } configure(); for (RouteDefinition route : getRouteCollection().getRoutes()) { route.markPrepared(); } } }
protected void populateRoutes() throws Exception { ModelCamelContext camelContext = getContext(); if (camelContext == null) { throw new IllegalArgumentException("CamelContext has not been injected!"); } getRouteCollection().setCamelContext(camelContext); //将所有路由定义取出,并且添加到CamelContext中 camelContext.addRouteDefinitions(getRouteCollection().getRoutes()); }
public synchronized void addRouteDefinitions(Collection<RouteDefinition> routeDefinitions) throws Exception { //遍历所有路由定义 for (RouteDefinition routeDefinition : routeDefinitions) { //如果路由定义已经存在则移除原有定义 removeRouteDefinition(routeDefinition); } //将所有路由定义添加到路由定义集合中 this.routeDefinitions.addAll(routeDefinitions); //判断是否要启动路由 if (shouldStartRoutes()) { startRouteDefinitions(routeDefinitions); } }
添加路由与跌幅的配置创建就讲完了,下面就是最重要的:路由定义的执行过程,即路由定义的启动过程,这个下回讲解......
标签:camel route routebuilder routedefinition
原文地址:http://blog.csdn.net/xtayfjpk/article/details/39103231