You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

SQL Example

Available as of Camel 2.11

This example is located in the examples/camel-example-sql directory of the Camel distribution.
There is a README.txt file with instructions how to run it.

If you use maven then you can easily compile and install the example from the command line:

mvn install

About

This example shows how to exchange data using a shared database table.

The example has two Camel routes. The first route insert new data into the table, triggered by a timer to run every 5th second.
The second route pickup the newly inserted rows from the table, process the row(s), and mark the row(s) as processed when done; to avoid picking up the same rows again.

Implementation

In the camel-context.xml file in the src/main/resources/META-INF/spring folder we have the Spring XML file to setup and configure the database, as well the CamelContext.

Error formatting macro: snippet: java.lang.NullPointerException

And then in the same file we setup our Camel application. At first we have a orderBean that we use in the routes to generate new orders and process orders as well.

Error formatting macro: snippet: java.lang.NullPointerException

Notice how we have externalized the SQL queries, and use Camels property placeholder to refer to the sql.properties file.

Error formatting macro: snippet: java.lang.NullPointerException

Running the example

This example can be run from the command line

mvn camel:run

Press ctrl + c to stop the example.

Running the example in OSGi such as Apache Karaf / ServiceMix

From Apache Karaf / ServiceMix shell you can install this example. You would need to install Camel first in Apache Karaf.
Camel is installed out of the box in Apache ServiceMix.

features:install camel-example-sql

When the example is running in Karaf / ServiceMix you can see in the log when it processes the orders, using

log:tail

See Also

  • No labels