8. Delta Publish and Subscribe¶
Introduction¶
Delta messaging in AMPS has two independent aspects:
- delta subscribe allows subscribers to receive just the fields that are updated within a message.
- delta publish allows publishers to update and add fields within a message by publishing only the updates into the SOW.
This chapter describes how to create delta publish and delta subscribe commands using the AMPS C++ client. For a discussion of this capability, how it works, and how message types support this capability see the AMPS User Guide.
Delta Subscribe¶
To delta subscribe, you simply use the delta_subscribe
command as
follows:
// assumes that client is connected and logged on
Command cmd("delta_subscribe");
cmd.setTopic("delta_topic");
cmd.setFilter("/thingIWant = 'true'");
for (auto m : client.execute(cmd))
{
// Delta messages arrive here
}
As described in the AMPS User Guide, messages provided to a delta subscription will contain the fields used to generate the SOW key and any changed fields in the message. Your application is responsible for choosing how to handle the changed fields.
Delta Publish¶
To delta publish, you use the delta_publish
command as follows:
/* assumes that client is connected and logged on */
String msg = ... ; // obtain changed fields here
client.deltaPublish("myTopic", msg);
The message that you provide to AMPS must include the fields that the
topic uses to generate the SOW key. Otherwise, AMPS will not be able to
identify the message to update. For SOW topics that use a User-Generated
SOW Key, use the Command
form of delta_publish
to set the
SowKey
.
/* assumes that client is connected and logged on */
String msg = ... ; // obtain changed fields here
String key = ... ; // obtain user-generated SOW key
Command cmd("delta_publish");
cmd.setTopic("delta_topic");
cmd.setSowKey(key);
cmd.setData(msg);
/* Execute the delta publish. Use an empty
* a message handler since any failure acks will
* be routed to the FailedWriteHandler
*/
client.executeAsync(cmd,MessageHandler());