如何使用消息排序部署发布订阅触发的云功能?
How to deploy pubsub-triggered cloud function with message ordering?
我想部署一个带有消息排序的 Pubsub 触发的 Cloud Functions:
https://cloud.google.com/pubsub/docs/ordering
gcloud functions deploy
没有设置 --enable-message-ordering
选项的选项:
https://cloud.google.com/sdk/gcloud/reference/functions/deploy
我应该在部署函数之前预先创建订阅吗?如果是这样,Cloud Functions 是否有一个众所周知的格式来匹配订阅名称?似乎格式可能是:gcf-{function-name}-{region}-{topic-name}
,但名称格式似乎也随时间发生了变化,例如较旧的已部署函数在订阅中没有区域名称。有稳定的方法吗?
您必须手动创建消息排序 pub/sub 和云函数。
首先,创建一个pub/sub主题,然后创建一个订阅pub/sub主题的订阅--enable-message-ordering
其次,创建一个云函数来处理有序的 pub/sub 消息。
最后,回到 pub/sub 订阅,编辑推送类型并指定您的云函数端点。
所以最终的图如下。
发布者 -> Pub/sub 主题 -> Pub/sub 订阅者 -> 云函数
您尝试直接将 Pub/sub 主题与云功能建立联系。
但对于消息排序,Pub/sub 需要主题 -> 订阅者连接。
所以只有 pub/sub 主题 -> pub/sub 订阅者 -> 云功能连接可以将有序消息传递到您的功能。
当声明 Pub/Sub topic 时,云函数类似:
exports.pubsub = functions.pubsub.topic('some-topic').onPublish((message, context) => {}
问题是消息排序仅适用于订阅,但不适用于主题。
部署时会在以下位置自动创建推送订阅:cloudpubsub/subscription/list
(the one which starts with gcf-*
). This only appears to work when manually subscribing to a topic: Enabling message ordering. I haven't yet tried if it would pick up a subscription with the same name; if everything fails, one still could record the messages and then order by timestamp or a "sequence token": https://www.youtube.com/watch?v=nQ9_Xur2aM4。
我想部署一个带有消息排序的 Pubsub 触发的 Cloud Functions: https://cloud.google.com/pubsub/docs/ordering
gcloud functions deploy
没有设置 --enable-message-ordering
选项的选项:
https://cloud.google.com/sdk/gcloud/reference/functions/deploy
我应该在部署函数之前预先创建订阅吗?如果是这样,Cloud Functions 是否有一个众所周知的格式来匹配订阅名称?似乎格式可能是:gcf-{function-name}-{region}-{topic-name}
,但名称格式似乎也随时间发生了变化,例如较旧的已部署函数在订阅中没有区域名称。有稳定的方法吗?
您必须手动创建消息排序 pub/sub 和云函数。
首先,创建一个pub/sub主题,然后创建一个订阅pub/sub主题的订阅--enable-message-ordering
其次,创建一个云函数来处理有序的 pub/sub 消息。
最后,回到 pub/sub 订阅,编辑推送类型并指定您的云函数端点。
所以最终的图如下。
发布者 -> Pub/sub 主题 -> Pub/sub 订阅者 -> 云函数
您尝试直接将 Pub/sub 主题与云功能建立联系。
但对于消息排序,Pub/sub 需要主题 -> 订阅者连接。
所以只有 pub/sub 主题 -> pub/sub 订阅者 -> 云功能连接可以将有序消息传递到您的功能。
当声明 Pub/Sub topic 时,云函数类似:
exports.pubsub = functions.pubsub.topic('some-topic').onPublish((message, context) => {}
问题是消息排序仅适用于订阅,但不适用于主题。
部署时会在以下位置自动创建推送订阅:cloudpubsub/subscription/list
(the one which starts with gcf-*
). This only appears to work when manually subscribing to a topic: Enabling message ordering. I haven't yet tried if it would pick up a subscription with the same name; if everything fails, one still could record the messages and then order by timestamp or a "sequence token": https://www.youtube.com/watch?v=nQ9_Xur2aM4。