英文:
Google Cloud Platform: Is there a way to ignore Pub/Sub messages if a Cloud Function is already processing?
问题
我对Google Cloud Platform非常陌生,目前正在使用Go语言创建一些云函数。我想知道是否可能创建一个订阅主题的云函数,在处理消息时忽略已经在处理的消息?
基本上,我的系统在某个时刻发送一个"done"消息,这会启动一个云函数。我希望如果该主题接收到另一个"done"消息,它不会启动另一个订阅函数实例,而是忽略该消息。
英文:
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.
答案1
得分: 1
我不确定是否可以在Cloud Function
中原生地实现这一点。
你可以考虑使用state
来处理这种情况。
例如,可以使用Google Cloud
中的memorystore
和Redis
来存储接收到的消息。
在你的Cloud Function
中,你可以使用Python
的Redis
客户端来访问缓存。
你可以添加一个过滤器,只处理缓存中不存在的消息。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论