Camel and Kura: Providing Telemetry Data as OPC UA
The upcoming version 2.1.0 of Eclipse Kura will feature an enhanced version of the Apache Camel integration which was introduced in Kura 2.0.0. There are various new ways on how to run Camel routes, configured either by XML routes or using the Java DSL. Apache Camel can act as a Kura application but, new in this release, there is also a way to simply configure Camel as a “cloud service.” In past releases of Kura, applications could only push data to one cloud target. The new 2.1.0 release will add the functionality of adding multiple cloud targets and one of those targets can be Apache Camel router instances.
With Camel you can have different ways of achieving this goal, but in this post I would like to focus on the “out of the box” way, by simply configuring (not developing) a set of Camel routes, which act as cloud service. Traditional instances of cloud services in Kura are only capable of delivering data to one cloud target or subscribing to one cloud infrastructure. But using Apache Camel as a technology it is possible to connect to a bunch of technologies at the same time.
The setup
The setup will be a Kura instance, running a pre-release version of Kura 2.1.0. The final version should be out in a few weeks and won’t differ much from the current version. We will be configuring a new cloud service instance which takes Kura application payload data and provide it as OPC UA, using the Camel OPC UA adapter. As payload provider (aka Kura application) we will be using the “Example publisher” from my Kura addons project.
Open up the Kura Web UI, navigate to “Packages” and select “Install/Update”. Switch to “URL” and provide the following URL:
https://dentrassi.de/download/kura/de.dentrassi.kura.addons.example.publisher_0.1.0-SNAPSHOT.dp
The installation may take a bit and it may be necessary to press the “Refresh” button in order to see the installed package. After the packages was installed you should be able to see the service “Camel example publisher” on the left side.
Now we need to install the “Milo component for Camel”. Press “Install/Update” again and enter the following URL:
https://dentrassi.de/download/kura/de.dentrassi.kura.addons.milo_0.1.0-pre1.dp
Updated after Eclipse Milo release:
http://central.maven.org/maven2/de/dentrassi/kura/addons/de.dentrassi.kura.addons.milo/0.2.2/de.dentrassi.kura.addons.milo-0.2.2.dp
This installation will take a lot longer and you will need to check again by pressing the “Refresh” button in the Web UI.
We will also need to allow TCP access to port 12685. If you have the network managed version of Kura installed switch to the UI section “Firewall” and open a new port “12685” allowing access from “0.0.0.0/0” (Permitted Network) and press “Apply”.
A New Cloud Service
By default, the “example publisher” will publish to the default Kura cloud service instance. We will now create a new Cloud service instance and then redirect the data to OPC UA. The data will be available as an OPC UA server. OPC UA differs between client and server. And while the Camel component does provide both ways, in this case the want others to consume our data, so offering data as an OPC UA server is the way to go.
Navigate to “Cloud Services” and press the “New” button. From the list of possible providers select org.eclipse.kura.camel.cloud.factory.CamelFactory
, enter a cloud service PID (e.g. camel-opcua
) and press “Create”.
After the instance has been created select it and configure it with the following options:
Router XML:
<routes xmlns="http://camel.apache.org/schema/spring">
<route id="opc-ua-example">
<from uri="vm:camel:example"/>
<split>
<simple>${body.metrics().entrySet()}</simple>
<setHeader headerName="item">
<simple>${body.key()}</simple>
</setHeader>
<setBody>
<simple>${body.value()}</simple>
</setBody>
<toD uri="my-milo:${header.item}"/>
</split>
</route>
</routes>
Initialization Code:
var milo = new org.apache.camel.component.milo.server.MiloServerComponent();
milo.setEnableAnonymousAuthentication(true);
camelContext.addComponent("my-milo", milo);
Assigning the Cloud Service
Now we need to configure the example publisher to actually use our new cloud service instance. Select “Camel example publisher” from the left navigation bar and enter “opcua” (or whatever PID you used before) as “Cloud Service PID”. Apply the changes.
Testing the Result
First of all, if you log in into your device using SSH, you should be able to see that port 12685 is opened:
root@raspberrypi:/home/pi# ss -nlt | grep 12685
LISTEN 0 128 :::12685 :::*
Now you can connect to your device using any OPC UA explorer to the URI: opc.tcp://<my-ip>:12685
I am using Android and the “ProSYS OPC UA Client”:
Summing it Up
This tutorial uses a SNAPSHOT version of Eclipse Milo. Simply due to the fact that no version of Milo is released just yet. This should change in the following weeks and my play is to update the blog post once it is available. However the functionality of Milo will not change and using the Camel component, most internals of Milo are hidden anyway.
Apache Camel on Eclipse Kura can provide a complete new way of communication. This example was a rather simple one, Camel can do a lot more when it comes to processing data. And not all real-life applications may be as easy as that. But of course the intention of this blog post was to give a quick introduction into Camel and Kura in combination. Using the Camel Java DSL or the Kura Camel programmatic API can give greater flexibility. And yet, the example shows that even with a few lines of Camel XML, amazing things can be achieved.