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.
await client.connect('wss://localhost:9000/amps/json');
// Original subscription
const subId = await client.execute(
new Command('subscribe').topic('orders').filter('/id > 100'),
onMessagePrinter
);
// Replace the subscription with a new filter value
await client.execute(
new Command('subscribe')
.topic('orders')
.filter('/id < 5')
.subId(subId)
.options('replace'),
onMessagePrinter
);