Cumulocity and Apama Integration

Cumulocity and Apama Integration:

Cumulocity gives you very fast visibility and control over your remote assets, be these houses, cars, machines or any other assets that you need to manage. It provides. Certified hardware kits and software libraries you can use to bring your remote assets into the cloud. Device management, data visualization, and remote control functionality through the web

Streaming Analytics (Apama) is “Software that can filter, aggregate, enrich, and analyze a high throughput of data from multiple, disparate live data sources and in any data, format to identify simple and complex patterns to provide applications with context to detect opportune situations, automate immediate actions, and dynamically adapt.”

Let us see, how to monitor the Cumulocity data that is coming in using Apama with this integration.

Create your first Apama project:

Start Software AG Designer and switch to the Apama Developer perspective.

From the wizard select Apama project in the Software AG folder and click Next. Type a project name, e.g. Tutorial1 and click Finish.

A new Apama project will be created. Expand the project in the Explorer view to see the auto generated folder structure.

Connect your local environment to Cumulocity Core:

In order to create and test your rules, your local Apama project needs to connect to a Cumulocity Core instance. This will allow us to receive and send events (measurements, alerts etc) from and to Cumulocity Core.

Right-click the newly created project and select Apama > Add Connectivity and Adapters.

From the list select Cumulocity IoT > Cumulocity IoT and click Ok.

Notice the new entry “Connectivity and Adapters” under your project in the Project Explorer view. Open the file CumulocityIoT.yaml under Connectivity and Adapters > Cumulocity IoT > Cumulocity IoT.

Add the following line to the end of the file and save it. It’s very important that the new line is indented by exactly the same number of spaces as the appKey-entry.

url: ${URL} 

Now open the file CumulocityIoT.properties. Add the following line to the end of the file:

URL=

As you can see there is one property called “CUMULOCITY_APPKEY”. Before we can fill the properties, we need to generate an app key first.

Login to your Cumulocity tenant and navigate to the Administration application. From the left navigation select “Own applications”.

Click on “Add application” and choose “External application”. Enter the following parameters:

Click on Save.

Go back to Software AG Designer with the CumulocityIoT.properties file. Now fill all the properties:

  • CUMULOCITY_USERNAME=<username to access your Cumulocity tenant>
  • CUMULOCITY_TENANT=<name of your tenant on cumulocity-dev.com>
  • CUMULOCITY_PASSWORD=<password to access your Cumulocity tenant>
  • CUMULOCITY_APPKEY=apama
  • URL=http://<your tenant>.cumulocity-dev.com

Save the changes.

Now right-click on your project and select Properties. Then select ApamaàMonitorScript Build PathàBundles. Add the bundle Automatic onApplicationInitialized (immediately start receiving from connectivity plug-ins and JMS). See the diagram below

Click ok and close.

Test the connection to Cumulocity Core:

We will create a simple EPL script that outputs every Measurement from Cumulocity Core to our console. This will confirm that the connection to Cumulocity Core can be established.

Right-click the monitor's folder in your project and select New > EPL Monitor.

Enter name and Package and click Finish.

Update your monitor with the script to monitor temperature measurements from Cumulocity core instance.

Let’s test our monitor and see if we can connect to our Cumulocity Core tenant. Right-click the project in the Project Explorer and select Run As > Apama Application.

Software AG Designer will now start a local Apama Correlator and inject your monitor file.

You can see the startup process in the Console view. If there is no error in the Console the correlator successfully started and connected to Cumulocity Core. Let’s send a temperature measurement and see if your correlator catches the event.

Start Postman and send the temperature measurements.

Hit the Send button – you should receive a 201 Created response. Go back to your Software AG Designer. You should immediately see a console output with the temperature event.

Deploy the monitor file to Cumulocity:

Until now the co-realtor was running outside and you can run the same monitor script from Cumulocity by uploading it to Cumulocity core.

Deploying the monitor file to Cumulocity is an easy task. Navigate to the Administration application in your browser.

Select “Own application” from the left navigation. Click Add application and select “Upload custom CEP rule”. Upload the monitor file you have created in Software AG Designer.

So from now on, this monitor file will be in active status and keeps monitoring any of the measurements that are coming in Cumulocity and provide the required output.