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.
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
).
Update the Camel routing XML file (
camel-route/src/main/resources/META-INF/spring/camel-context.xml
)Start the command line.
Change the working directory to the Camel module you want to update (
camel
-route
in our example).Build the updated project by executing the
mvn install
command.Drop the
camel-route/target/camel-route-1.0-SNAPSHOT.jar
file to theSERVICEMIX_HOME/deploy
directory.
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&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.
Versioning of the modules deployed to ServiceMix is a powerful tool that can be used to simultaneously manage multiple versions of the same module.
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).