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 JavaScript 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:

const subId = await client.execute(

  // The delta_subscribe command to execute
  new Command('delta_subscribe')
      .filter('/thingIWant = "true"'),

  // Message handler
  message => { /* Delta messages arrive here */ }


// Once subscribed, it resolves with the subscription id.

Example 8.1: Using delta_subscribe Command

The convenience method Client.deltaSubscribe() is available. If the delta_subscribe is not a valid command for the topic provided, a regular subscription will be created.

const subId = await client.deltaSubscribe(
  message => { /* ... */ },  // Message handler
  'delta-topic',             // Topic
  '/thingIWant = "true"'     // Filter (optional)

// Once subscribed, it resolves with the subscription id.

Example 8.2: Using deltaSubscribe()

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 Client.deltaPublish() method as follows:

const data = ... ;  // obtain changed fields here
client.deltaPublish('my-topic', data);

Example 8.3: Using deltaPublish()

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.

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

const command = new Command('delta_publish');

* Execute the delta publish. Do not provide a message
* handler since delta_publish is not waiting for the
* acknowledgment from the server.

Example 8.4: Using delta_publish command for topics with user-generated SOW keys