Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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.

Image AddedImage Removed

KuraRouter activator

...

Code Block
languagejava
public class MyKuraRouter extends KuraRouter {

    @Override
    public void configure() throws Exception {
		ServiceReference<MyService> serviceRef = bundleContext.getServiceReference(LogService.class.getName());
		MyService myService = contentbundleContext.getService(serviceRef);
        ...
    }

}

...

Code Block
languagejava
public class MyKuraRouter extends KuraRouter {

    @Override
    public void configure() throws Exception {
		camelContext.getStatus();
        ...
    }

}

ProducerTemplate

Protected member producerTemplate is the ProducerTemplate instance associated with the given Camel context.

Code Block
languagejava
public class MyKuraRouter extends KuraRouter {

    @Override
    public void configure() throws Exception {
		producerTemplate.sendBody("jms:temperature", 22.0);
   		...
    }

}

ConsumerTemplate

Protected member consumerTemplate is the ConsumerTemplate instance associated with the given Camel context.

Code Block
languagejava
public class MyKuraRouter extends KuraRouter {

    @Override
    public void configure() throws Exception {
		double currentTemperature = producerTemplate.receiveBody("jms:temperature", Double.class);
        ...
    }

}

OSGi service resolver

...

Code Block
languagejava
public class MyKuraRouter extends KuraRouter {

    @Override
    public void configure() throws Exception {
		MyService myService = service(MyService.class);
        ...
    }

}

If service is not found, a null value is returned. If you want your application to fail if the service is not available, use requiredService(Class) method instead. The requiredService throws IllegalStateException if a service cannot be found.

Code Block
languagejava
public class MyKuraRouter extends KuraRouter {

    @Override
    public void configure() throws Exception {
		MyService myService = requiredService(MyService.class);
        ...
    }

}

KuraRouter activator callbacks

...

Code Block
languagejava
public class MyKuraRouter extends KuraRouter {
 
  ...

  protected void beforeStart(CamelContext camelContext) {
    OsgiDefaultCamelContext osgiContext = (OsgiCamelContext) camelContext;
    osgiContext.setName("NameOfTheRouter");
  }

}

Loading XML routes from ConfigurationAdmin

Sometimes 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 KuraRouter looks for the kura.camel.BUNDLE-SYMBOLIC-NAME.route property from the kura.camel PID using the OSGi ConfigurationAdmin. This approach allows you to define Camel XML routes file per deployed KuraRouter. In order to update a route, just edit an appropriate configuration property and restart a bundle associated with it. The content of the kura.camel.BUNDLE-SYMBOLIC-NAME.route property is expected to be Camel XML route file, for example:

Code Block
<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 service

If you would like to deploy your Kura router as a declarative OSGi service, you can use activate and deactivate methods provided by KuraRouter.

Code Block
<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>

Include Page
Endpoint See Also
Endpoint See Also