...
Kura router starts its own OSGi-aware CamelContext
. It means that for every class extending KuraRouter
, there will be a dedicated CamelContext
instance. Ideally we recommend to deploy one KuraRouter
per OSGi bundle.
Camel properties
Deploying KuraRouter
Bundle containing your Kura router class should import the following bundles in the OSGi manifest:Spring Boot auto-configuration automatically connect Spring Boot external configuration (like properties placeholders, OS environment variables or system properties) with the Camel properties support. It basically means that any property defined in application.properties
file:
Code Block | ||||
---|---|---|---|---|
| ||||
route.from = jms:invoices | ||||
Import-Package: org.osgi.framework;version="1.3.0",
org.slf4j;version="1.6.4",
org.apache.camel,org.apache.camel.impl,org.apache.camel.core.osgi,org.apache.camel.builder,org.apache.camel.model,
org.apache.camel.kura |
Keep in mind that you don't have to import every Camel component bundle you plan to use in your routes, as Camel components are resolved as the services on the runtime level.
Before you deploy your router bundle, be sure that you have deployed (and started) the following Camel core bundles (using Kura GoGo shell)...or set via system property...
Code Block | ||||
---|---|---|---|---|
| ||||
java -Droute.to=jms:processed.invoices -jar mySpringApp.jar |
...can be used as placeholders in Camel route:
Code Block | ||
---|---|---|
| ||
@Component
public class MyRouter extends RouteBuilder {
@Override
public void configure() throws Exception {
from("{{route.from}}").to("{{route.to}}");
}
} |
Custom Camel context configuration
If you would like to perform some operations on CamelContext
bean created by Camel auto-configuration, register CamelContextConfiguration
instance in your Spring context:
Code Block | ||
---|---|---|
| ||
@Configuration
public class MyAppConfig {
...
@Bean
CamelContextConfiguration contextConfiguration() {
return new CamelContextConfiguration() {
@Override
void beforeApplicationStart(CamelContext context) {
// your custom configuration goes here
}
};
}
} |
Method CamelContextConfiguration#
beforeApplicationStart(CamelContext)
will be called just before the Spring context is started, so the CamelContext
instance passed to this callback is fully auto-configured. You can add many instances of CamelContextConfiguration
into your Spring context - all of them will be executed.
Disabling JMX
To disable JMX of the auto-configured CamelContext
use camel.springboot.jmxEnabled
property (JMX is enabled by default). For example you could add the following property to your application.properties
file:
install file:///home/user/.m2/repository/org/apache/camel/camel-core/2.15.0/camel-core-2.15.0.jar
start <camel-core-bundle-id>
install file:///home/user/.m2/repository/org/apache/camel/camel-core-osgi/2.15.0/camel-core-osgi-2.15.0.jar
start <camel-core-osgi-bundle-id>
install file:///home/user/.m2/repository/org/apache/camel/camel-kura/2.15.0/camel-kura-2.15.0.jar
start <camel-kura-bundle-id> |
...and all the components you plan to use in your routes:
Code Block | ||||
---|---|---|---|---|
| ||||
install file:///home/user/.m2/repository/org/apache/camel/camel-stream/2.15/camel-stream-2.15.jar
start <camel-kura-bundle-id> |
Then finally deploy your router bundle:
Code Block | ||||
---|---|---|---|---|
| ||||
install file:///home/user/.m2/repository/com/example/myrouter/1.0/myrouter-1.0.jar
start <your-bundle-id> | ||||
Code Block | ||||
xml | xml | camel.springboot.jmxEnabled = false |
Auto-configured consumer and producer templates
Camel auto-configuration provides a pre-configured ConsumerTemplate
and ProducerTemplate
instances. You can simply inject them into your Spring-managed beans:
...