Apache camel shared datasource
This short comment intends to explain the usage of HSQLDB as a shared data source for Apache camel using camel-blueprint. As a result, any possible camel routes can be linked to the created shared data source. Furthermore, you can use a JDBC database of your choice.
You need to install the following bundles:
- camel-blueprint
- camel-stream
- camel-csv
- camel-sql
HikariCP is used as JDBC connection pool.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
<?xml version="1.0" encoding="UTF-8"?> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"> <bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig"> <property name="jdbcUrl" value="jdbc:hsqldb:hsql://localhost/HSQLDB" /> <property name="maximumPoolSize" value="10" /> <property name="idleTimeout" value="60000" /> <property name="username" value="sa" /> <property name="password" value="" /> </bean> <bean id="HSQLDataSource" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close"> <argument ref="hikariConfig" /> </bean> <service interface="javax.sql.DataSource" ref="HSQLDataSource"> <service-properties> <entry key="osgi.jndi.service.name" value="hsqldb"/> </service-properties> </service> </blueprint> |
The camel-blueprint route for CSV file with pipe “|” delimiter:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<?xml version="1.0" encoding="UTF-8"?> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"> <reference id="hsqldb" interface="javax.sql.DataSource"/> <camelContext xmlns="http://camel.apache.org/schema/blueprint" id="Import"> <route id="CSVImport"> <from uri="file:csvfiles?delete=true" /> <split id="SplitRecords" streaming="true" parallelProcessing="true"> <tokenize token="\n" /> <unmarshal> <csv delimiter="|" lazyLoad="true"/> </unmarshal> <transform> <simple>${body[0]}</simple> </transform> <log id="logEachCSVRecord" loggingLevel="INFO" message="Process CSV record: ${body}"/> <to uri="sql:INSERT INTO CSVTABLE(COL1, COL2) VALUES(#,#)?dataSource=hsqldb"/> </split> </route> </camelContext> </blueprint> |
Spelling error report
The following text will be sent to our editors: