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. By default, all of these updates are sent. However, using the YAML configuration file, you can configure whether you want to subscribe to them; see
Configuring the Cumulocity IoT transport.
Notifications about measurements are only received by the Cumulocity IoT transport if the processing mode in Cumulocity IoT is PERSISTENT or TRANSIENT (and not QUIESCENT or CEP).
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.
Note:
This subscription makes use of the long-polling real-time notifications feature of Cumulocity IoT. Note that this is not recommended for high-throughput use cases. See also the information on real-time notifications in the
Cumulocity IoT - API Specifications at
https://cumulocity.com/api/.
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;
}
}
}
}