使用 Google Cloud Pub/Sub 时,如何在 AWS/SQS 中实现 "locked" 功能?

How to implement the "locked" feature in AWS/SQS when using Google Cloud Pub/Sub?

当您想在 Google 云 Pub/Sub 上实施 producer/consumer 模式时,您会期望每条消息只能由一个消费者处理。但是 Google Cloud Pub/Sub 会将每条消息发送给所有订阅者。

但是 AWS/SQS 具有以下功能可以轻松保证这一点:

When a message is received, it becomes “locked” while being processed. This keeps other computers from processing the message simultaneously. If the message processing fails, the lock will expire and the message will be available again. In the case where the application needs more time for processing, the “lock” timeout can be changed dynamically via the ChangeMessageVisibility operation.

如何在 Google 云 Pub/Sub 之上实施 producer/consumer 模式?或者有其他替代方案Google云产品?

Google Cloud Pub/Sub 有类似的机制。请记住,并非每个 订阅者 都会收到每条消息,每个 订阅者 都会收到每条消息。区别很重要。单个订阅可以有多个订阅者,同时拉取消息,同时处理同一个订阅的不同消息。

在单个订阅中,当一条消息被发送给一个订阅者时,在订阅创建时指定的确认截止日期(默认值为 10 秒)内,它不会被发送给该订阅的另一个订阅者。接收消息的订阅者必须在 ack 截止日期之前确认消息或延长 ack 截止日期,这允许它花费更长的时间来处理消息,而不会将消息传递给其他订阅者。某些客户端库会自动处理延长确认期限,例如 Java and Go, while others require the explicit modification of the ack deadline, e.g., Python。 ack 截止时间的行为方式与 SQS 的可见性超时相同。

有关详细信息,请参阅 message acknowledgement deadline