Apama 10.15.0 | Connecting Apama Applications to External Components | Standard Connectivity Plug-ins | The Cumulocity IoT Transport Connectivity Plug-in | Using operations
 
Using operations
 
Creating a new operation
Updating an existing operation
Querying for operations
The com.apama.cumulocity.Operation event represents a device operation. If the configuration option subscribeToOperations is enabled (see Configuring the Cumulocity IoT transport) or if you Subscribe to the operations stream, this event is sent to the com.apama.cumulocity.Operation.SUBSCRIBE_CHANNEL (same as cumulocity.operations) channel. This event contains the unique identifier of the operation (id), the identifier of the source (deviceId), a status, and optional parameters.
Example of an operation:
Operation("12345", "deviceId", "EXECUTING", params)
where params is a dictionary of string keys and any values (dictionary<string, any>).
Make sure to set the deviceId field to the identifier of a managed object which has the com_cumulocity_model_Agent fragment. The com_cumulocity_model_Agent marks devices running a Cumulocity IoT agent. Such devices receive all operations targeted to themselves and their children for routing (see also Device integration using REST in Cumulocity IoT's Device SDK guide).
When creating a new operation, do not supply the id field (that is, supply an empty string for the operation identifier).
It is not possible to set the params field of an operation to an empty dictionary.
Example
The following is a simple example of how to receive, create and send operations:
// Subscribe to receive all the operations published from Cumulocity IoT

monitor.subscribe(Operation.SUBSCRIBE_CHANNEL);

on all Operation() as o {
log o.toString() at INFO;

// Update an operation
o.status := "EXECUTING";
send o to Operation.SEND_CHANNEL;
}

// Create an operation
Operation operation := new Operation;
operation.source := "<MANAGED_OBJECT_ID>";
operation.status := "PENDING";
operation.params.add("c8y_Message", {"text": "Device Operation"});
send operation to Operation.SEND_CHANNEL;