Apama 10.15.5 | Connecting Apama Applications to External Components | Standard Connectivity Plug-ins | The Cumulocity IoT Transport Connectivity Plug-in | Receiving update notifications
 
Receiving update notifications
The Cumulocity IoT transport can receive update notifications on new measurements, events, alarms, managed objects and operations that are processed by the Cumulocity IoT platform. To receive these notifications, you must add either the Cumulocity Notifications 2.0 bundle (recommended) or the Cumulocity Client bundle (deprecated). For details on how to add the bundles, see Loading the Cumulocity IoT transport.
Note: 
The Cumulocity Client bundle makes use of the long-polling real-time notifications feature of Cumulocity IoT. This is not recommended for high-throughput use cases, and it will not receive messages if they are sent in the QUIESCENT or CEP processing modes. It only receives messages if they are sent in the PERSISTENT or TRANSIENT processing modes. We recommend using the Notifications 2.0 bundle instead, which does not have these limitations.
When a notification about a managed object, operation, alarm or event is sent, the params dictionary member will contain a property which signals whether the notification is a new object or an update to an existing object. The property name is in the constant PARAM_NOTIFICATION and has the value corresponding to the value of the constants NOTIFICATION_CREATED or NOTIFICATION_UPDATED. The recommended way to distinguish between create and update events is to use the isCreate() and isUpdate() actions which are available on these events, as shown in the example below.
Measurements are not modifiable in Cumulocity IoT, so all measurement notifications are newly-created objects.
Example:
using com.apama.cumulocity.ManagedObject;
using com.apama.cumulocity.ManagedObjectDeleted;
using com.apama.cumulocity.Measurement;
using com.apama.cumulocity.MeasurementDeleted;
using com.apama.cumulocity.Event;
using com.apama.cumulocity.EventDeleted;
using com.apama.cumulocity.Alarm;
using com.apama.cumulocity.Operation;

monitor NotificationListener {
action onload {
// Subscribe for notification for managed objects
monitor.subscribe(ManagedObject.SUBSCRIBE_CHANNEL);
// Subscribe for notification for measurements
monitor.subscribe(Measurement.SUBSCRIBE_CHANNEL);
// Subscribe for notification for events
monitor.subscribe(Event.SUBSCRIBE_CHANNEL);
// Subscribe for notification for alarms
monitor.subscribe(Alarm.SUBSCRIBE_CHANNEL);
// Subscribe for notification for operations
monitor.subscribe(Operation.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;
}

// Listen for notifications for measurements
on all Measurement() as measurement {
// Measurements can only be created
log "Measurement created" at INFO;
}

// Listen for notifications on deleted measurements
on all MeasurementDeleted() as measurementDeleted {
log "Measurement deleted" at INFO;
}

// Listen for notifications for events
on all Event() as evt {
if evt.isCreate() {
log "Event created" at INFO;
}
else if evt.isUpdate() {
log "Event updated" at INFO;
}
}

// Listen for notifications on deleted events
on all EventDeleted() as eventDeleted {
log "Event deleted" at INFO;
}

// Listen for notifications for alarms
on all Alarm() as alarm {
if alarm.isCreate() {
log "Alarm created" at INFO;
}
else if alarm.isUpdate() {
log "Alarm updated" at INFO;
}
}

// Listen for notifications for operations
on all Operation() as operation {
if operation.isCreate() {
log "Operation created" at INFO;
}
else if operation.isUpdate() {
log "Operation updated" at INFO;
}
}
}
}