gpt4 book ai didi

java - 每次推送消息时AWS SQS : Is it a way SQS call me consumer,

转载 作者:行者123 更新时间:2023-12-01 20:55:06 28 4
gpt4 key购买 nike

AWS SQS 是否可以通过某种方式调用我的 REST API?基本上,一旦消息被推送到 AWS SQS,我就想听到它并执行所需的操作。我可以安排一个每秒可以提取消息的监听器,但这不是一个优化解决方案,而且队列可能是空的(有时)。

提前致谢!!

最佳答案

一些想法:

使用发布者/订阅者

考虑在 SNS/SQS 中使用发布者-订阅者模型,以便将消息发布到 SNS 并通过 SQS 订阅该消息。如果您绝对需要在消息发布后立即对其进行处理,您可以发布到 SNS,并在 SQS 订阅之外设置另一个消费者(例如调用您的 Rest API 的 lambda subscriber?)来处理它。

SQS 长轮询

关于 SQS,听起来您会从长轮询中受益。来自文档:

Long polling helps reduce your cost of using Amazon SQS by reducing the number of empty responses (when there are no messages available to return in reply to a ReceiveMessage request sent to an Amazon SQS queue) and eliminating false empty responses (when messages are available in the queue but aren't included in the response):

  • Long polling reduces the number of empty responses by allowing Amazon SQS to wait until a message is available in the queue before sending a response. Unless the connection times out, the response to the ReceiveMessage request contains at least one of the available messages, up to the maximum number of messages specified in the ReceiveMessage action.
  • Long polling eliminates false empty responses by querying all (rather than a limited number) of the servers.
  • Long polling returns messages as soon any message becomes available.

另外,根据文档,要以编程方式启用长轮询,请对任何这些 SQS 操作使用以下命令:

引用:

关于java - 每次推送消息时AWS SQS : Is it a way SQS call me consumer,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42496336/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com