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.
sub_cmd = AMPS.Command("sow_and_subscribe") \
.set_topic("orders-sow") \
.set_sub_id("A42") \
.set_filter("/details/items/description LIKE 'puppy'")
client.execute_async(sub_cmd, MyHandler)
# Elsewhere in the program...
replace_cmd = AMPS.Command("sow_and_subscribe") \
.set_topic("orders-sow") \
.set_sub_id("A42") \
.set_filter("/details/items/description LIKE 'kitten'") \
.set_options("replace")
client.execute_async(replace_cmd, MyHandler)