Changing the Filter on a Subscription
AMPS allows you to update parameters, such as the content filter, on a subscription. When you replace a filter on the subscription, AMPS immediately begins sending only messages that match the updated filter. Notice that if the subscription was entered with a command that includes a SOW query, using the replace
option can re-issue the SOW query (as described in the AMPS User Guide).
To update the filter on a subscription, you create a subscribe
command. You set the SubscriptionId
provided on the Command
to the identifier of the existing subscription and include the replace
option on the Command
.
When you send the Command
, AMPS atomically replaces the filter and sends messages that match the updated filter from that point forward.
// Assumes client is connected and logged on to AMPS
// Enter subscription
Command subscribe_cmd = new Command("sow_and_subscribe")
.setTopic("orders-sow")
.setSubId("A42") // Used later for replace
.setFilter("/details/items/description LIKE 'puppy'");
MyHandler mh = new MyHandler();
client.executeAsync(subscribe_cmd, mh);
// ...
// Replace filter elsewhere in the program
Command replace_cmd = new Command("sow_and_subscribe")
.setTopic("orders-sow")
.setSubId("A42") // A42 is the ID of the subscription to replace
.setFilter("/details/items/description LIKE 'kitten'")
.setOptions("replace");
client.executeAsync(replace_cmd, mh);
Last updated