简体   繁体   English

GCP 发布/订阅消息的确认行为

[英]Acknowledgement Behaviour of GCP Pub/sub messages

I'm working on micro-service that contains subscriptions to a topic in GCP Pub/Sub.我正在研究包含对 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?我希望一旦订阅者确认,pub/sub 就不会进一步发送消息,但是如果不同主机上同一订阅的两个订阅者同时收到消息怎么办,是否会导致重复?

Pub/Sub delivers each published message at least once for every subscription. Pub/Sub 为每个订阅至少传递一次已发布的消息。

https://cloud.google.com/pubsub/docs/subscriber#at-least-once-delivery 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.这意味着同一系统可能会收到两次相同的命令。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM