blob: 117917713a51710844f1c90e5dcf6d299d982515 [file] [log] [blame]
h1. Deployment options
There are a few different ways to deploy Camel routes on ServiceMix ${servicemx.version}:
* deploy routes in a plain Spring XML file
* deploy a bundle containing
*# routes defined in a Spring XML file
*# routes defined in the Java or Scala DSL
Camel routes can also be deployed as part of a JBI SA, allowing you use Camel for routing between JBI endpoints - this option will be discussed later when we are talking about using JBI inside ServiceMix 4.
h2. Deploy as a plain Spring XML file
ServiceMix ${servicemix.version} supports the deployment of plain Spring XML files, automatically creating and starting the Spring ApplicationContext from the XML file.
In order to leverage this feature to create and start Camel routes, drop a file with this syntax in the {{$SERVICEMIX_HOME/deploy}} folder:
{code:lang=xml}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/spring"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring-${camel-version}.xsd">
<camelContext xmlns="http://camel.apache.org/schema/spring">
<!-- add Camel routes, interceptors,... here -->
</camelContext>
</beans>
{code}
h3. An example
Just create a new XML file in the deploy folder with the code below to start a route to copy files from one directory to another.
{code:lang=xml}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/spring"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring-${camel-version}.xsd">
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="file:input"/>
<log message="Copying ${file:name} to the output directory"/>
<to uri="file:output"/>
</route>
</camelContext>
</beans>
{code}
h2. Deploy as an OSGi bundle
The Spring XML file can also be deployed as part of a bundle by adding it to the {{META-INF/spring}} folder. When the bundle is being started, the Spring ApplicationContext is created and started as well. This kind of deployment also allows using Java or Scala Routebuilders for defining the routes.
h3. Using the XML file to define the routes
The route can be defined directly in the XML file you add to {{META-INF/spring}}, similar to the example shown before.
h3. Using a Java or Scala RouteBuilder
When using a Java (or Scala) RouteBuilder to define your Camel routes, the Spring XML file refers to the packages containing the RouteBuilder classes:
{code:lang=xml}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/spring"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring-${camel-version}.xsd">
<camelContext xmlns="http://camel.apache.org/schema/spring">
<package>org.apache.servicemix.manual.camel</package>
</camelContext>
</beans>
{code}
The matching Java RouteBuilder class could look like this
{code:lang=java}
package org.apache.servicemix.manual.camel;
import org.apache.camel.builder.RouteBuilder;
public class MyRouteBuilder extends RouteBuilder {
public void configure() {
from("file:input")
.log("Copying ${file:name} to the output directory")
.to("file:output");
}
}
{code}
A similar Scala RouteBuilder could look like
{code:lang=scala}
package org.apache.servicemix.manual.camel;
import org.apache.camel.scala.dsl.builder.RouteBuilder;
class MyRouteBuilder extends RouteBuilder {
"file:input" ==> {
log("Copying ${file:name} to the output directory")
to("file:output")
}
}
{code}