This Confluence has been LDAP enabled, if you are an ASF Committer, please use your LDAP Credentials to login. Any problems file an INFRA jira ticket please.

Child pages
  • SQL Example

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

...

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

Code Block

mvn install

...

About

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

...

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.

Wiki Markup
{snippet:id=e1|lang=xml|title=Setting up database|url=camel/trunk/examples/camel-example-sql/src/main/resources/META-INF/spring/camel-context.xml}

...

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.

Wiki Markup
{snippet:id=e2|lang=xml|title=Camel application|url=camel/trunk/examples/camel-example-sql/src/main/resources/META-INF/spring/camel-context.xml}

...

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

...

Notice in the SQL queries below we use named parameters which must start with prefix ':#' and then the name, eg :#amount. Then Camel will bind that parameter with the given name, from the
message body (if its a java.util.Map) or from a message header with the name. If none parameter could be found, Camel throws an exception.

Wiki Markup
{snippet:id=e1|title=SQL queries|url=camel/trunk/examples/camel-example-sql/src/main/resources/sql.properties}

...

Running the example

This example can be run from the command line

Code Block

mvn camel:run

...

Press ctrl + c to stop the example.

...