Book Image

Instant Apache ServiceMix How-to

By : Henryk Konsek
Book Image

Instant Apache ServiceMix How-to

By: Henryk Konsek

Overview of this book

<p>Creating reliable integration solution can be easy if you choose the right tools for the job. Apache Camel and ServiceMix are the leading integration technologies dedicated to dealing with the complexity of the messaging solutions. Learn how to efficiently integrate multiple systems with bleeding edge open source Apache software.</p> <p>"Instant Apache ServiceMix How-to" is a practical, hands-on guide that provides you with a number of clear, step-by-step exercises that will help you take advantage of the real power that is behind the leading Apache integration stack.</p> <p>This book guides the reader in how to install ServiceMix and how to get it up and running. It will take you through a number of practical recipes – starting with the basic commands of Apache Karaf container and ending with the deployment of JMS and web service solutions.</p>
Table of Contents (7 chapters)

Updating Camel routes at runtime (Should know)


One of the most important features provided by ServiceMix is the ability to redeploy a given module without restarting the whole container. This recipe will demonstrate how to redeploy the Camel routing module created in the previous recipe.

Getting ready

In the previous recipe you learned how to create and deploy a new Camel route module into your ServiceMix instance. In this recipe, we will show you how to update the routing module without restarting ServiceMix.

To make this recipe as simple as possible, we will demonstrate how to update the Camel routing module created in the previous recipe. Let's assume that you modified the routing module by changing the camel-context.xml file in the route project (just as a reminder, the file is located at camel-route/src/main/resources/META-INF/spring/camel-context.xml).

How to do it...

  1. Update the Camel routing XML file (camel-route/src/main/resources/META-INF/spring/camel-context.xml)

  2. Start the command line.

  3. Change the working directory to the Camel module you want to update (camel -route in our example).

  4. Build the updated project by executing the mvn install command.

  5. Drop the camel-route/target/camel-route-1.0-SNAPSHOT.jar file to the SERVICEMIX_HOME/deploy directory.

How it works...

Camel routing modules can be deployed to ServiceMix without restarting the container. As soon as ServiceMix detects that a new version of the Camel routing module has been dropped into the deploy directory, it replaces the existing version of the bundle with the new one. For example, you could enrich your Camel context with the following route:

  <camel:route>
     <camel:from uri="file:///home/inbox"/>
     <camel:to uri="log:FROM-DIRECTORY"/>
  </camel:route>

The preceding routing rule reads files from the /home/inbox directory and sends their content as messages to the dedicated logger. After this modification, your Camel context will look liike the following XML snippet:

<camel:camelContext xmlns="http://camel.apache.org/schema/spring">
  <camel:route>
    <camel:from uri="timer://myTimer?fixedRate=true&amp;period=5000"/>
     <camel:to uri="log:EXAMPLE-ROUTE"/>
   </camel:route>
  <camel:route>

<camel:from uri="file:///home/inbox"/>
   <camel:to uri="log:FROM-DIRECTORY"/>
</camel:route>

After you redeploy the route, you will see that the /home/inbox directory will be automatically created by Camel. If you try to drop a text file into this directory, it will be picked up by Camel and sent to the ServiceMix logger.

There's more...

Versioning of the modules deployed to ServiceMix is a powerful tool that can be used to simultaneously manage multiple versions of the same module.

Bundles provisioning

The version of the Maven artifact representing the Camel route is also the version of the OSGI bundle. This means that if you update the version of the Maven module, you can also deploy two versions of a similar route running concurrently in ServiceMix. This behavior is very useful when you want to preserve the older version of the route for legacy clients. Remember, however, that similar routes deployed to the same container may generate conflicts (for example, if two consumer endpoints read from the data source that does not support concurrent access).