@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") } }) ctx.start() // exchangeを作成して、endpointに送信 endpoint = ctx.getEndpoint("direct:customer") exc = endpoint.createExchange() exc.getIn().setBody("insert into customer values (1011, 'michael')") template = ctx.createProducerTemplate() out = template.send(endpoint, exc) if( !out.isFailed() ){ // 件数を出力 println "inserted:" + out.getOut().getHeader( org.apache.camel.component.jdbc.JdbcConstants.JDBC_UPDATE_COUNT ) } else { println "Failed:" + out.getException().getMessage() } ctx.stop()
動作環境
groovy 1.8.5, JDK7 Update2, Apache Camel 2.9.0
0 件のコメント:
コメントを投稿