Eclipse Kura component
This documentation page covers the integration options of Camel with the Eclipse Kura M2M gateway.
KuraRouter activator
The easiest way to deploy Apache Camel routes into the Kura is to create an OSGi bundle containing the class extending org.apache.camel.kura.KuraRouter
class:
public class MyKuraRouter extends KuraRouter { @Override public void configure() throws Exception { from("timer:trigger"). to("netty-http:http://app.mydatacenter.com/api"); } }
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.
Deploying KuraRouter
Bundle containing your Kura router class should import the following bundles in the OSGi manifest:
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)...
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:
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:
install file:///home/user/.m2/repository/com/example/myrouter/1.0/myrouter-1.0.jar start <your-bundle-id>
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:
@Component public class InvoiceProcessor { @Autowired private ProducerTemplate producerTemplate; @Autowired private ConsumerTemplate consumerTemplate; public void processNextInvoice() { Invoice invoice = consumerTemplate.receiveBody("jms:invoices", Invoice.class); ... producerTemplate.sendBody("netty-http:http://invoicing.com/received/" + invoice.id()); } }
By default consumer and producer templates comes with the endpoint cache sizes equal to 1000. You can change that values via the following Spring properties:
camel.springboot.consumerTemplateCacheSize = 100 camel.springboot.producerTemplateCacheSize = 200
Auto-configured TypeConverter
Camel auto-configuration registers TypeConverter
instance named typeConverter
in the Spring context.
@Component public class InvoiceProcessor { @Autowired private TypeConverter typeConverter; public long parseInvoiceValue(Invoice invoice) { String invoiceValue = invoice.grossValue(); return typeConverter.convertTo(Long.class, invoiceValue); } }
Spring type conversion API bridge
Spring comes with the powerful type conversion API. Spring API happens not to be much different from the Camel type converter API. As those APIs are so similar, Camel Spring Boot automatically registers bridge converter (SpringTypeConverter
) that delegates to the Spring conversion API. It basically means that out-of-the-box Camel will threat Spring Converters as Camel ones. With this approach you can enjoy both Camel and Spring converters accessed via Camel TypeConverter
API:
@Component public class InvoiceProcessor { @Autowired private TypeConverter typeConverter; public UUID parseInvoiceId(Invoice invoice) { // Using Spring's StringToUUIDConverter UUID id = invoice.typeConverter.convertTo(UUID.class, invoice.getId()); } }
Under the hood Camel Spring Boot delegates conversion to the Spring's ConversionService
instances available in the application context. If no ConversionService
instance is available, Camel Spring Boot auto-configuration will create one for you.
Disabling type conversions features
If you don't want Camel Spring Boot to register type-conversions related features (like TypeConverter
instance or Spring bridge) set the camel.springboot.typeConversion
property to false
.
camel.springboot.typeConversion = false
Fat jars and fat wars
The easiest way to create Camel-aware Spring Boot fat jar/war is to extend the org.apache.camel.spring.boot.F
class...atJarRouter
package com.example; ... // imports @SpringBootApplication public class MyFatJarRouter extends FatJarRouter { @Override public void configure() throws Exception { from("netty-http:http://0.0.0.0:18080"). setBody().simple("ref:helloWorld"); } @Bean String helloWorld() { return "helloWorld"; } }
...and add the following property to your application.properties
file:
spring.main.sources = com.example.MyFatJarRouter
It is also recommended to define your main class explicitly in the Spring Boot Maven plugin configuration:
<plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>${spring-boot.version}</version> <configuration> <mainClass>com.example.MyFatJarRouter</mainClass> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin>
In order to turn your fat jar into fat war, add the following class extending org.apache.camel.spring.boot.F
to your project:atWarInitializer
package com.example; ... // imports public class MyFatWarInitializer extends FatWarInitializer { @Override protected Class<? extends FatJarRouter> routerClass() { return MyFatJarRouter.class; } }