8. Delta Publish and Subscribe


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.setFilter("/thingIWant = 'true'");

for (Message m in client.execute(cmd))
    // Work with message 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

msg = ... ; // obtain changed fields here
key = ... ; // obtain user-generated SOW key

Command cmd("delta_publish");

// Execute the delta publish. Use null for
// a message handler since any failure acks will
// be routed to the FailedWriteHandler