@Grab(group='postgresql', module='postgresql', version='9.1-901.jdbc4') @Grab(group="org.apache.camel", module="camel-core", version="2.9.0") @Grab(group="org.apache.camel", module="camel-jdbc", 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.* // 接続先DataSource ds = new org.postgresql.ds.PGPoolingDataSource() ds.setDataSourceName("userdb_ds") ds.setServerName("localhost") ds.setDatabaseName("userdb") ds.setUser("postgres") ds.setPassword("postgres") // DataSourceをレジストリに設定 registry = new SimpleRegistry() registry.put("userdb_ds", ds) ctx = new DefaultCamelContext(registry) ctx.addRoutes(new RouteBuilder(){ void configure() { from("direct:customer") .to("jdbc:userdb_ds?readSize=100") .process( { exc -> for( row in exc.getIn().getBody() ){ // 各列を出力 println row.get("customer_id") println row.get("customer_name") } } as Processor ) } }) ctx.start() // exchangeを作成して、endpointに送信 endpoint = ctx.getEndpoint("direct:customer") exc = endpoint.createExchange() exc.getIn().setBody("select * from customer") template = ctx.createProducerTemplate() template.send(endpoint, exc) ctx.stop()
動作環境
groovy 1.8.5, JDK7 Update1, Apache Camel 2.9.0
0 件のコメント:
コメントを投稿