4
votes

For various reasons we have run into scenarios where we would like to "pause" push notifications from a Google Cloud Platform (GCP) Pubsub subscription and just allow them to queue up, and then eventually "unpause" and allow pushes to continue without losing any messages.

  1. Is this a built in feature?
  2. Can you suggest a workaround?
3
I'm not seeing it as a pubsub api feature - successhawk

3 Answers

4
votes

Good news. I stumbled upon the answer at https://cloud.google.com/pubsub/docs/subscriber#receive_push

Stopping/pausing and resuming push delivery

To pause receiving messages for a subscription, send a modifyPushConfigRequest to set the push endpoint to an empty string. The messages will accumulate, but will not be delivered. To resume receiving messages, send another modifyPushConfigRequest request with a populated push endpoint.

To permanently stop delivery, you should delete the subscription.

2
votes

There is no "pause" feature with push subscriptions. If you can, you might consider switching to a pull subscription. Then you can control exactly when you request messages.

If you can't switch to a pull subscription, you could just return an error response when you receive messages or make your endpoint unavailable. Google Cloud Pub/Sub will backoff redelivery of messages, waiting up to 10 seconds between attempts. It will try to redeliver messages for 7 days. Depending on how long you need to pause your message consumption, this might be a viable option.

If your not going to need to switch between "paused" and "unpaused" frequently, less than once per minute, then you can accomplish this behavior by switching your subscriber to a pull subscription (and not pulling) to get the pause behavior and then switching back to a push subscription to start receiving messages again.

0
votes

I don't think there's such a pause feature. Instead, you can use polling Consumers and you can stop polling when you need to pause. That's all I can think of.