标签:camel route routebuilder routedefinition
个人认为Camel中最重要的两大块,一是路由的构建过程,二是路由构建完成后的执行过程。camelContext.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { this.from("file:H:/temp/in").process(new Processor() { @Override public void process(Exchange exchange) throws Exception { GenericFile<File> gf = exchange.getIn().getBody(GenericFile.class); File file = gf.getFile(); PrintStream ps = new PrintStream(System.out); BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file))); String line = null; while((line=br.readLine())!=null) { ps.println(line); } ps.close(); br.close(); } }).to("file:H:/temp/out"); } });
public RouteDefinition from(String uri) { getRouteCollection().setCamelContext(getContext()); RouteDefinition answer = getRouteCollection().from(uri); configureRoute(answer); return answer; }
public RouteDefinition from(String uri) { //创建RouteDefinition对象 RouteDefinition route = createRoute(); route.from(uri); return route(route); } protected RouteDefinition createRoute() { //创建RouteDefinition对象 RouteDefinition route = new RouteDefinition(); ErrorHandlerFactory handler = getErrorHandlerBuilder(); if (handler != null) {//为RouteDefinition设置错误处理器 route.setErrorHandlerBuilderIfNull(handler); } return route; }
public RouteDefinition from(String uri) { //创建一个FromDefinition对象,并将其添加到路由定义的输入当中 getInputs().add(new FromDefinition(uri)); //返回当前RouteDefinition对象 return this; }
public RouteDefinition route(RouteDefinition route) { //预处理RouteDefinition,设置一些异常处理器,拦截器等 RouteDefinitionHelper.prepareRoute(getCamelContext(), route, getOnExceptions(), getIntercepts(), getInterceptFroms(), getInterceptSendTos(), getOnCompletions()); //将预处理好的RouteDefinition添加到RouteDefinition集合当中,这样Camel就知道多了一个路由定义 getRoutes().add(route); //标记该路由定义已处理好 route.markPrepared(); //返回当前的RouteDefinition对象 return route; }
public Type process(Processor processor) { ProcessDefinition answer = new ProcessDefinition(processor); addOutput(answer); //这时的this不是ProcessDefinition对象,而是RouteDefinition对象 return (Type) this; }
public Type to(String uri) { addOutput(new ToDefinition(uri)); return (Type) this; }
标签:camel route routebuilder routedefinition
原文地址:http://blog.csdn.net/xtayfjpk/article/details/39102025