如何实现“锁定"功能?使用Google Cloud Pub/Sub时在AWS/SQS中使用功能吗? [英] How to implement the "locked" feature in AWS/SQS when using Google Cloud Pub/Sub?

查看:116
本文介绍了如何实现“锁定"功能?使用Google Cloud Pub/Sub时在AWS/SQS中使用功能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您想在Google Cloud Pub/Sub之上实现生产者/消费者模式时,您希望每条消息只能由一个消费者处理.但是Google Cloud Pub/Sub会将每条消息发送给所有订阅者.

When you want to implement a producer/consumer pattern on top of Google Cloud Pub/Sub, you would expect each message can only be processed by one consumer. But Google Cloud Pub/Sub would send each message to all the subscribers.

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

But the AWS/SQS has the following feature to easy guarantee this:

当接收到一条消息时,它在处理过程中将变为锁定"状态. 这样可以防止其他计算机同时处理该消息. 如果消息处理失败,则锁将过期,并且消息 将再次可用.在应用程序需要更多的情况下 处理时间,可以通过以下方式动态更改锁定"超时时间: ChangeMes​​sageVisibility操作.

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 Cloud Pub/Sub之上实施生产者/消费者模式?还是还有其他替代的Google Cloud产品?

How to implement the producer/consumer pattern on top of Google Cloud Pub/Sub? Or there is other alternative Google Cloud product?

推荐答案

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

Google Cloud Pub/Sub has a similar mechanism. Keep in mind that not every subscriber will receive every message, every subscription will receive every message. The distinction is important. There can be multiple subscribers for a single subscription, pulling messages simultaneously and processing different messages for the same subscription simultaneously.

在单个订阅中,当消息发送到订阅者时,在订阅创建时指定的ack截止时间(默认值为10秒)下,不会将消息发送到该订阅的另一个订阅者.收到消息的订户必须在确认截止期限之前确认该消息或延长确认截止期限,这使它可以花更长的时间来处理该消息,而无需将消息传递给其他订户.某些客户端库中会自动处理ack截止期限的自动处理,例如,开始,而其他人则需要明确修改ack截止日期,例如

Within a single subscription, when a message is sent to a subscriber, it will not be sent to another subscriber for that subscription for the ack deadline specified at subscription creation time (default value is 10 seconds). The subscriber that receives the message has until the ack deadline to acknowledge the message or extend the ack deadline, which allows it to take longer to process the message without the message being delivered to other subscribers. Extending the ack deadline is handled automatically in some of the client libraries, e.g., Java and Go, while others require the explicit modification of the ack deadline, e.g., Python. The ack deadline behaves the same way as SQS's visibility timeout.

有关更多信息,请参见消息确认截止期限.

See message acknowledgement deadline for more information.

这篇关于如何实现“锁定"功能?使用Google Cloud Pub/Sub时在AWS/SQS中使用功能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆