@Grab(group="org.apache.camel", module="camel-core", version="2.9.0") @Grab(group="org.apache.camel", module="camel-csv", version="2.9.0") @Grab(group="org.slf4j", module="slf4j-simple", version="1.6.4") //@Grab(group="org.slf4j", module="slf4j-nop", version="1.6.4") import org.apache.camel.* import org.apache.camel.builder.* import org.apache.camel.impl.* ctx = new DefaultCamelContext() ctx.getShutdownStrategy().setTimeout(5) ctx.addRoutes(new RouteBuilder(){ void configure() { // CSVファイルを読み込む from("file://c:/share/camel?fileName=in.csv&noop=true") .routeId("myroute") .unmarshal().csv() .process( { exc -> def sb = new StringBuffer() for( line in exc.getIn().getBody() ){ // 2列目の文字列がgroovyなら出力 if( line.get(1) == 'groovy' ){ sb.append(line.join(',')) sb.append('\n') } } exc.getOut().setBody(sb) } as Processor ) // 別のファイルに出力 .to("file://c:/share/camel?fileName=out.csv") .process( { exc -> exc.getContext().getInflightRepository().remove(exc) exc.getContext().stopRoute("myroute") } as Processor ) } }) ctx.start() while(!ctx.getRouteStatus("myroute").isStopped()){ println "waiting..." Thread.sleep(1000) }
動作環境
groovy 1.8.5, JDK7 Update1, Apache Camel 2.9.0
0 件のコメント:
コメントを投稿