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

huangapple go评论80阅读模式
英文:

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中的memorystoreRedis来存储接收到的消息。

在你的Cloud Function中,你可以使用PythonRedis客户端来访问缓存。
你可以添加一个过滤器,只处理缓存中不存在的消息。

英文:

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.

huangapple
  • 本文由 发表于 2022年12月12日 07:53:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/74765455.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定