How to detect a change in a Managed Object with an EPL APP?

What product/components do you use and which version/fix level are you on?

Cumulocity
1011.0.17

Is your question related to the free trial, or to a production (customer) instance?

Production

What are you trying to achieve? Please describe it in detail.

Using an EPL App, I would like to monitor the inventory for changes in Managed Objects with the fragment IsMatterDevice{}.

In this object I have a fragment which I would like extract attributes from, totalise them and update another fragment in the object, each time the managed object changes.

I believe I need to subscribe to the ManagedObject events and monitor the NOTIFICATION_UPDATED parameter. But it’s not clear to me how I do that? I was hoping for some code samples? Also I expect there to be a lot of there devices (1000s), so the solution should be scalable…

For reference, I’m happy to update this value anytime any fragment changes in the managed object.

Thanks

Hi Harrison,
In EPL you can monitor for changes in Managed Objects with something like the following (and for your changes you just need the update section)

...
    // Subscribe for notification for managed objects
    monitor.subscribe(ManagedObject.SUBSCRIBE_CHANNEL);

    // Listen for notifications for managed objects
    on all ManagedObject() as managedObject {
        if managedObject.isCreate() {
            log "ManagedObject created" at INFO;
        }
        else if managedObject.isUpdate() {
            log "ManagedObject updated" at INFO;
        }
    }

    // Listen for notifications on deleted managed objects
    on all ManagedObjectDeleted() as managedObjectDeleted {
        log "ManagedObject deleted" at INFO;
    }
...

You can find this information in the Apama documentation
Search for “Receiving update notifications” it is under the section “The Cumulocity IoT Transport Connectivity Plug-in”

Receiving update notifications (softwareag.com)

I see you’re on version 10.11, Are you using Cumulocity Cloud or Edge? If it is Cumulocity Cloud, 10.11 is quite an old version and we would recommend updating to a newer version

With regards scalability, especially if there are 1000’s of devices, Please note that if you expect a large number of events at any one time, that the outgoing calls from Apama to Cumulocity will be processed in serial through the httpClient until the later version of 10.15.

Another thing to keep an eye out for is potential cycles. If this could be an issue perhaps something you need to consider are separate child Managed Objects, of different types, for the calculated value. Otherwise when you update the calculated value, you could end up in a situation where you get another notification of change.

Hope this helps,
Regards,
Sharon

2 Likes

Hi Harrison,

you will find the fragment IsMatterDevice{} in the params dictionary of the ManagedObject. So, following Sharon’s suggestions, you should find the updates to the ManagedObjects with :

using com.apama.cumulocity.ManagedObject;

monitor ListenOnManagedObjects {
	action onload() {
		log "Loaded monitor ListenOnManagedObjects" at INFO;
		monitor.subscribe(ManagedObject.SUBSCRIBE_CHANNEL);
		on all ManagedObject() as mo {
			if (mo.isUpdate() and mo.params.hasKey("IsMatterDevice")) {
				log "# ManagedObject" + mo.toString() at INFO;
				//Add your code here
			}
			
		}
	}
}

Felix

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.