GCP Pub/sub 消息的确认行为

发布于 2025-01-16 01:41:29 字数 215 浏览 1 评论 0原文

我正在开发包含 GCP Pub/Sub 中某个主题的订阅的微服务。由于微服务的多个实例在多个主机(云上的多个集群)上运行,我想知道来自订阅的消息的确认行为。当一个实例上的订阅接收、处理并确认消息时,其他主机上的相同订阅是否也会收到该消息?

我希望一旦订阅者确认,发布/订阅就不会进一步发送消息,但是如果不同主机上同一订阅的两个订阅者同时收到消息怎么办,是否会导致重复?

I'm working on micro-service that contains subscriptions to a topic in GCP Pub/Sub. As multiple instances of a Microservices run on more than one host (multiple clusters on cloud), I wanted to know acknowledging behaviour of messages from subscriptions. When a subscription on one instance receives, process and acknowledges the message, does the same subscription on other hosts receive the message?

I expect that once the subscriber acknowledges, pub/sub doesn't further send the message, but what if two subscribers on same subscription on different hosts receives message at the same time, does it cause duplication?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

╰つ倒转 2025-01-23 01:41:29

对于每个订阅,Pub/Sub 至少传递每条已发布消息一次。

https://cloud.google.com/pubsub/docs/ subscriber#at-least-once-delivery

如果您希望多个“工作人员”不接收消息克隆,则需要对所有这些“工作人员”使用单个订阅。

这是因为对于事件,您可以让多个系统在不同的订阅上侦听同一主题,以便所有系统都会收到已发生事件的事件。

对于命令,您通常需要一个系统来处理它们(即使在多个工作人员之间分配),因此您需要在所有工作人员之间共享的单个订阅。

顺便说一句,您的系统在处理来自主题的事件/命令时应该幂等。一般经验法则是,每条消息都保证被订户至少接收一次。这意味着同一系统可能会两次接收相同的命令。

Pub/Sub delivers each published message at least once for every subscription.

https://cloud.google.com/pubsub/docs/subscriber#at-least-once-delivery

If you want multiple "workers" to not receive message clones, you need to use a single subscription for all of them.

This is because for events you can have multiple systems listening on the same topic, on different subscriptions so that all the systems receive the event that something has happened.

For commands, you usually want a single system to handle them (even if split between multiple workers) so you would need a single subscription that is shared among all the workers.

By the way, your system should be idempotent in processing events/commands from a topic. The general rule of thumb is that each message is guaranteed to be received by a subscriber at least one time. Meaning the same system could potentially receive the same command two times.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文