Eclipse Kura is an OSGi based framework dedicated for the M2M gateways based on the small computing platforms like Raspberry Pi or BeagleBoard Black. If you consider using Kura in your M2M gateway and and the same time you would like to take advantage of the rich set of Apache Camel components and its EIP capabilities, then Camel Kura component is something for you. Camel Kura component will be available starting from the Camel 2.15.0.
Camel Kura architecture
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. The diagram below demonstrates the architecture of the Camel solution deployed into the Eclipse Kura:How can I activate my route?
Bundles 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
org.apache.camel.kura.KuraRouter
class:
Keep in mind that
KuraRouter
implements the org.osgi.framework.BundleActivator
interface, so you need to register its start
and stop
lifecycle methods while creating Kura bundle component class.
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.How can I deploy my KuraRouter
Bundle containing your Kura router class should import the following packages in the OSGi manifest:
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)...
...and all the components you plan to use in your routes:
Then finally deploy your router bundle:
Some KuraRouter utilities to make your life easier
Kura router base class provides many useful utilities. Let 's explore some of them.
SLF4J logger
Kura uses SLF4J facade for logging purposes. Protected member
log
returns SLF4J logger instance associated with the given Kura router.
BundleContext
Protected member
bundleContext
returns bundle context associated with the given Kura router.
CamelContext
Protected member
camelContext
is the CamelContext
associated with the given Kura router.OSGi service resolver
OSGi service resolver (
service(Class serviceType)
) can be used to easily retrieve service by type from the OSGi bundle context.How can I configure CamelContext used by KuraRouter?
Kura router comes with the lifecycle callbacks that can be used to customize the way the Camel router works. For example to configure the
CamelContext
instance associated with the router just before the former is started, override beforeStart
method of the KuraRouter
class: