Since we're on a major migration process of this website, some component documents here are out of sync right now. In the meantime you may want to look at the early version of the new website
https://camel.apache.org/staging/
We would very much like to receive any feedback on the new site, please join the discussion on the Camel user mailing list.
Eclipse Kura componentKura component is available starting from Camel 2.15. This documentation page covers the integration options of Camel with the Eclipse Kura M2M gateway. The common reason to deploy Camel routes into the Eclipse Kura is to provide enterprise integration patterns and Camel components to the messaging M2M gateway. For example you might want to install Kura on Raspberry PI, then read temperature from the sensor attached to that Raspberry PI using Kura services and finally forward the current temperature value to your data center service using Camel EIP and components. KuraRouter activatorBundles deployed to the Eclipse Kura are usually developed as bundle activators. So the easiest way to deploy Apache Camel routes into the Kura is to create an OSGi bundle containing the class extending public class MyKuraRouter extends KuraRouter { @Override public void configure() throws Exception { from("timer:trigger"). to("netty-http:http://app.mydatacenter.com/api"); } } Keep in mind that Kura router starts its own OSGi-aware Deploying KuraRouterBundle containing your Kura router class should import the following packages 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.component.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.0/camel-stream-2.15.0.jar start <camel-stream-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> KuraRouter utilitiesKura router base class provides many useful utilities. This section explores each of them. SLF4J loggerKura uses SLF4J facade for logging purposes. Protected member public class MyKuraRouter extends KuraRouter { @Override public void configure() throws Exception { log.info("Configuring Camel routes!"); ... } } BundleContextProtected member public class MyKuraRouter extends KuraRouter { @Override public void configure() throws Exception { ServiceReference<MyService> serviceRef = bundleContext.getServiceReference(LogService.class.getName()); MyService myService = bundleContext.getService(serviceRef); ... } } CamelContextProtected member public class MyKuraRouter extends KuraRouter { @Override public void configure() throws Exception { camelContext.getStatus(); ... } } ProducerTemplateProtected member public class MyKuraRouter extends KuraRouter { @Override public void configure() throws Exception { producerTemplate.sendBody("jms:temperature", 22.0); ... } } ConsumerTemplateProtected member public class MyKuraRouter extends KuraRouter { @Override public void configure() throws Exception { double currentTemperature = producerTemplate.receiveBody("jms:temperature", Double.class); ... } } OSGi service resolverOSGi service resolver ( public class MyKuraRouter extends KuraRouter { @Override public void configure() throws Exception { MyService myService = service(MyService.class); ... } } If service is not found, a public class MyKuraRouter extends KuraRouter { @Override public void configure() throws Exception { MyService myService = requiredService(MyService.class); ... } } KuraRouter activator callbacksKura router comes with the lifecycle callbacks that can be used to customize the way the Camel router works. For example to configure the public class MyKuraRouter extends KuraRouter { ... protected void beforeStart(CamelContext camelContext) { OsgiDefaultCamelContext osgiContext = (OsgiCamelContext) camelContext; osgiContext.setName("NameOfTheRouter"); } } Loading XML routes from ConfigurationAdminSometimes it is desired to read the XML definition of the routes from the server configuration. This a common scenario for IoT gateways where over-the-air redeployment cost may be significant. To address this requirement each <routes xmlns="http://camel.apache.org/schema/spring"> <route id="loaded"> <from uri="direct:bar"/> <to uri="mock:bar"/> </route> </routes>
Deploying Kura router as a declarative OSGi serviceIf you would like to deploy your Kura router as a declarative OSGi service, you can use <scr:component name="org.eclipse.kura.example.camel.MyKuraRouter" activate="activate" deactivate="deactivate" enabled="true" immediate="true"> <implementation class="org.eclipse.kura.example.camel.MyKuraRouter"/> </scr:component> |