I am doing Apache Camel PoC in my project. I am stuck at one issue when using Camel JDBC component.
I can read from the database with JDBC component. But I need to use Timer component always. As per the Camel documentation JDBC component cannot be used in from() statement. I tried using Direct component in from() statement as given in the documentation but it doesn’t work.
Below is my code:
from("direct:zh_ICS_Test")
//from("timer://myTimer?period=2s")
.setBody(constant("select * from ZH_ICS_TEST"))
.to("jdbc:myDataSource")
.split(body())
.convertBodyTo(String.class)
.to("file://" + dst);
Below is the console output:
[main] INFO org.apache.camel.impl.DefaultCamelContext - Apache Camel 2.12.1 (CamelContext: camel-1) is starting [main] INFO org.apache.camel.management.ManagedManagementStrategy - JMX is enabled [main] INFO org.apache.camel.impl.converter.DefaultTypeConverter - Loaded 176 type converters [main] INFO org.apache.camel.impl.DefaultCamelContext - StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html [main] INFO org.apache.camel.impl.DefaultCamelContext - Route: route1 started and consuming from: Endpoint[direct://zh_ICS_Test] [main] INFO org.apache.camel.impl.DefaultCamelContext - Total 1 routes, of which 1 is started. [main] INFO org.apache.camel.impl.DefaultCamelContext - Apache Camel 2.12.1 (CamelContext: camel-1) started in 0.798 seconds [main] INFO org.apache.camel.impl.DefaultCamelContext - Apache Camel 2.12.1 (CamelContext: camel-1) is shutting down [main] INFO org.apache.camel.impl.DefaultShutdownStrategy - Starting to graceful shutdown 1 routes (timeout 300 seconds) [Camel (camel-1) thread #1 - ShutdownTask] INFO org.apache.camel.impl.DefaultShutdownStrategy - Route: route1 shutdown complete, was consuming from: Endpoint[direct://zh_ICS_Test] [main] INFO org.apache.camel.impl.DefaultShutdownStrategy - Graceful shutdown of 1 routes completed in 0 seconds [main] INFO org.apache.camel.impl.DefaultCamelContext - Apache Camel 2.12.1 (CamelContext: camel-1) uptime 5.818 seconds [main] INFO org.apache.camel.impl.DefaultCamelContext - Apache Camel 2.12.1 (CamelContext: camel-1) is shutdown in 0.016 seconds
Above code works if I use Timer instead of Direct component. I don’t want to use Timer always and just need to execute my query once. I am using Camel 2.12.1 with JDK7.
Can someone please help?