简体   繁体   English

Google Cloud Functions 无法使用 Pub/Sub 死信主题

[英]Google Cloud Functions can't use Pub/Sub dead-letter topic

It seems GCP Cloud Functions always ACK Pubsub PUSH messages when invoked, even if function crashes or fails.似乎 GCP Cloud Functions 在调用时总是 ACK Pubsub PUSH 消息,即使 function 崩溃或失败。

This prevents the use of the new Pub/Sub "dead-letter" topic feature, which required message delivery to fail before forwarding it to a different topic.这可以防止使用新的 Pub/Sub“死信”主题功能,该功能需要消息传递失败,然后才能将其转发到不同的主题。 Presently, messages never fail.目前,消息永远不会失败。

Is there a way to utilize "dead-letter topic" or pubsub re-delivery with Cloud Functions?有没有办法利用 Cloud Functions 的“死信主题”或 pubsub 重新交付? Apart for setting the "retry" flag on the function itself, that doesn't solve this issue.除了在 function 本身上设置“重试”标志外,这并不能解决这个问题。

A push subscription impies 2 things:推送订阅意味着两件事:

  • create your function in --trigger-http mode在 --trigger-http 模式下创建您的 function
  • create a push PUSH subscription that use the Cloud Functions URL.创建使用 Cloud Functions URL 的推送 PUSH 订阅。

Here you have created a function in --trigger-topic mode, it's a background function.在这里,您在 --trigger-topic 模式下创建了一个 function,它是一个背景 function。

You have here what you have to do for marking the function as failed .您在这里可以将 function 标记为 failed

Share your code if you need more help如果您需要更多帮助,请分享您的代码

One way that this can be handled (until GCP starts supporting manual acknowledgement for cloud function) is by re-queueing to the same topic with the retry count incremented in case of failure.可以处理这种情况的一种方法(直到 GCP 开始支持云功能的手动确认)是通过重新排队到相同的主题,并在失败的情况下增加重试计数。 You can store the retry counts in the payload itself like:您可以将重试计数存储在有效负载本身中,例如:

{
  "retry_count": 1,
  "data": {...}
}

Also to avoid the a faulty message being retried permanently, you can configure it to push to the dead-letter instead if the retry attempts > x.此外,为了避免错误消息被永久重试,您可以将其配置为在重试尝试 > x 时推送到死信。

This only solved the problem if the topi has only one subscriber though.这仅在 topi 只有一个订阅者的情况下才解决了问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过转发到死信主题来限制 Google Pub/Sub 交付尝试? - How to limit Google Pub/Sub delivery attempts by forwarding to a dead-letter topic? 使用 Cloud Functions、Pub/Sub 和死信队列/主题时,我的方法是否正确? - Is my approach right when using Cloud Functions, Pub/Sub and Dead-letter queues/topics? 谷歌云发布/订阅 - 订阅者未将消息转发到死信主题 - Google cloud Pub/Sub - subscriber not forwarding messages to dead letter topic 我可以在不同的Google Cloud项目中使用Google Cloud Pub / Sub吗? - Can I use Google Cloud Pub/Sub across different Google Cloud projects? 如何在发布/订阅主题上使用IoT遥测事件? - How can I use IoT telemetry events on Pub/Sub topic? Google Cloud Functions:Pub/Sub 与 Rest 触发 - Google Cloud Functions: Pub/Sub vs Rest triggering 我需要帮助调试 Pub/Sub Google Cloud Functions - I need help debugging Pub/Sub Google Cloud Functions 无法使用Google Cloud Function将数据从Google Pub / Sub获取到BigQuery - Can't get data from Google Pub/Sub to BigQuery with Google Cloud Function 如何使用 Terraform 配置 GCP 发布/订阅死信 - How to configure GCP pub/sub dead letter with Terraform 跨多个 Cloud Functions 分发 1 个 Pub/Sub 主题消息而不重复 - Distribute 1 Pub/Sub Topic Messages across multiple Cloud Functions without repetition
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM