Reputation: 21
I am working on an application that uses camel, spring DSL and is packaged as a jar via maven. On my local machine, I am able to start the application using maven camel:run.
But I am not sure if this is what I should be using in test/prod like environments. As for such environments, I should also have support to start / stop the application.
I have read elsewhere that there are different deployment/run options available - http://java.dzone.com/articles/apache-camel-deployment-modes
Can someone please suggest what is the best way to start a camel application (jar) which is using spring application context? If its a similar to having a main class that loads the spring context, what support can I add to allow a shutdown to be invoked on the application?
Upvotes: 2
Views: 1643
Reputation: 6853
You can use the maven-shade-plugin to build an executable jar. The main class is the one that hveiga mentioned. Depending on the OS there are several ways how to run a Java process as a service/daemon. On linux we nohup the java processes through a init.d script, on Windows we use the java service wrapper.
One downside of the shader plugin is that you need to manage how name clashes of resources in the individual jars are resolved. This is the configuration that works for us:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.5</version>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.apache.camel.spring.Main</mainClass>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.tooling</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/cxf/bus-extensions.txt</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer">
<resource>META-INF/INDEX.LIST</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer">
<resource>META-INF/MSFTSIG.SF</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer">
<resource>META-INF/MSFTSIG.RSA</resource>
</transformer>
</transformers>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
Upvotes: 0
Reputation: 6925
There are few ways of getting your routes started and stopped dynamically. There is a class called Main provided in camel-spring to be able to manage your XML routes (http://camel.apache.org/running-camel-standalone-and-have-it-keep-running.html). You could implement a service that watches a directory for new XML files and start the route everytime you drop files there. For doing this could either you the new WatchService available in Java 7 or use Apache Commons VFS2.
You can also go with the OSGi approach using Apache Karaf which provides features to manage routes out-of-the-box (http://camel.apache.org/karaf.html). However, maybe the learning curve for this approach is bigger if you don't know about OSGi.
Upvotes: 0