Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practices for draining or clearing a Google Cloud pubsub topic [closed]

For pubsub topics with number of messages in the range of ~100k, what is the best practice for draining/dropping/clearing/deleting all messages using gcloud-java SDK?

Possible solutions:

  • Deleting and recreating the subscribers and then the publishers

  • High concurrency pull+ack (easy to hit the quota this way)

  • Something else

My hope is that this process can be fast (not more than ~60 seconds, say), robust, and uses supported SDK methods with minimal other code.

like image 512
DrMarshall Avatar asked Sep 08 '16 18:09

DrMarshall


People also ask

How long do messages stay in Pubsub?

The default message retention duration is 7 days and the default expiration period is 31 days. To create a subscription with retention of acked messages enabled, follow these steps: In the Google Cloud console, go to the Pub/Sub subscriptions page.

Can Pubsub hold millions of messages?

There is no limit on the number of retained messages.

What is a dead letter in a pub sub service?

Dead-letter topic Maximum number of delivery attempts: A numeric value that signifies the number of delivery attempts that Pub/Sub makes for a specific message. If the subscriber client cannot acknowledge the message within the configured number of delivery attempts, the message is forwarded to a dead-letter topic.

What happens if two subscribers use the same subscription to pull messages from a topic in Google pub sub?

In the process of redelivering the outstanding message, Pub/Sub holds back and tries not to deliver the outstanding message to any other subscriber on the same subscription.


1 Answers

Update with description of snapshot and seek feature: One can use seek on a Pub/Sub subscription to ack older messages by seeking to a timestamp corresponding to now. The best way is via the gcloud command line tool. The command to acknowledge messages published up to a particular timestamp would be:

gcloud pubsub subscriptions seek <subscription path> --time=yyyy-mm-ddThh:mm:ss 

To delete all messages up to now:

gcloud pubsub subscriptions seek <subscription path> --time=$(date +%Y-%m-%dT%H:%M:%S)  

Previous answer prior to the addition of snapshot and seek: Currently, Google Cloud Pub/Sub has no way clear older messages, though it is something we are looking to add. Deleting and recreating the subscription would be the most efficient way to clear it, both in terms of time and cost. You wouldn't have to do anything with your publishers; any messages published from the point after recreation on will be sent to subscribers on the recreated subscription.

like image 173
Kamal Aboul-Hosn Avatar answered Oct 12 '22 14:10

Kamal Aboul-Hosn