Using Camel

Now that we know how to operate Apache ServiceMix through the shell console, it's time to start using it for what it is built for. Let's build our very first integration solution with a Camel route and deploy it on ServiceMix.

Our simple scenario

In this simple scenario, we're going to move files from an input directory called camel/input to an output directory called camel/output. To ensure we can keep track of which files get moved, we'll also write a message to the log file whenever we move a file.

Creating the route

One of the most simple ways to deploy a new route on ServiceMix, is by defining the route in a Blueprint XML file.

<?xml version="1.0" encoding="UTF-8"?>

    <camelContext xmlns="">
        <from uri="file:camel/input"/>
        <log message="Moving ${file:name} to the output directory"/>
        <to uri="file:camel/output"/>


Deploying the route

In order to deploy and start the route, just copy the XML file you created into ServiceMix' deploy directory. The file will get picked up and deployed by ServiceMix. You will see a camel/input folder appear in your ServiceMix installation directory and any files you copy into that directory will get moved into the camel/output directory.

If you do a log:display in the shell, you will also see the log output for every file that's been moved.

Using the shell to manage the route

Using osgi:list, you'll notice that your XML file has been transformed into a bundle and that the Blueprint container has been created to start your Camel route.

From this output, you also learn that the bundle id for your XML file is 200. This allow you to start and stop the route whenever necessary. Let's give this a go now...

First, stop the route with

karaf@root> osgi:stop 200

The route is no longer active, so any files you copy into the orders/input folder will remain there for now. As soon as you restart the route, the pending files will get moving again.

karaf@root> osgi:start 200