Search code examples
gogoogle-cloud-platformgoogle-cloud-functionsgoogle-cloud-pubsub

Google Cloud Platform: Is there a way to ignore Pub/Sub messages if a Cloud Function is already processing?


I am very new to Google Cloud Platform, and I am currently making some Cloud Functions in Go. I am wondering if it is possible to for a Cloud Function that is a subscriber to a topic to ignore a message if it is already processing one?

Essentially, my system sends a "done" message at some point, which spins up a Cloud function, I want to make it so that if that topic receives another done message, it doesn't start another subscriber function instance, but ignores the message.


Solution

  • I am not sure it's possible to do that natively with a Cloud Function.

    You can think having a state to handle this kind of use cases.

    For example there is memorystore with Redis in Google Cloud to store your received messages.

    In your Cloud Function, you can use a Python Redis client to access to cache. You can add a filter a treat only the messages that doesn't exist in the cache.