AWS SQS:每次推送消息时,SQS 是否以这种方式称呼我为消费者

AWS SQS: Is it a way SQS call me consumer, every time a messages is pushed

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

提前致谢!!

几个想法:

使用Publisher/Subscriber

考虑将发布者-订阅者模型与 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 操作中的任何一个使用以下命令:

参考:

听起来您最好使用 SNS 而不是 SQS。您想让 SQS 做什么,SNS 的设计目的是什么:

You can use Amazon SNS to send notification messages to one or more HTTP or HTTPS endpoints. When you subscribe an endpoint to a topic, you can publish a notification to the topic and Amazon SNS sends an HTTP POST request delivering the contents of the notification to the subscribed endpoint. When you subscribe the endpoint, you select whether Amazon SNS uses HTTP or HTTPS to send the POST request to the endpoint. If you use HTTPS, then you can take advantage of the support in Amazon SNS for the following...

http://docs.aws.amazon.com/sns/latest/dg/SendMessageToHttp.html