Reputation: 781
I need this ability to send push notifications for an action in a mobile app but wait for the user to undo the action until say 10 seconds.
Is it possible to delay the processing of a message published in a topic by 10 seconds ? And then (sometimes, if user does undo) delete the message before 10 seconds, if it doesn't need to be processed ?
Upvotes: 20
Views: 19791
Reputation: 4286
Depends on if you write the subscribers as well or not:
You have control over your subscriber's code:
If you don't have control over your subscriber you can have a my-topic
and my-delayed-topic
. Folks can publish to the former topic and that topic will have only one subscriber which you will implement:
my-topic
.my-delayed-topic
.You can also implement the logic above with task-queue+pubsub-topic instead of pubsub-topic+pubsub-topic.
Upvotes: 27
Reputation: 92
If architecturally possible at all, you could use Cloud Tasks. This API has the following features that might suit your usecase:
Assuming that your client has a storage for some task Ids:
schedule_time
set to 10s
in the future.DeleteTask
.Upvotes: 3
Reputation: 5453
Just wanted to share that I noticed Pub/Sub supports retry policies 1 that are GA as of 2020-06-16 2.
If the acknowledgement deadline expires or a subscriber responds with a negative acknowledgement, Pub/Sub can send the message again using exponential backoff.
If the retry policy isn't set, Pub/Sub resends the message as soon as the acknowledgement deadline expires or a subscriber responds with a negative acknowledgement.
If the maximum backoff duration is set, the default minimum backoff duration is 10 seconds. If the minimum backoff duration is set, the default maximum backoff duration is 600 seconds.
The longest backoff duration that you can specify is 600 seconds.
Upvotes: 2