python - AWS SQS ReceiveMessage 收到的消息少于请求的消息?

标签 python amazon-web-services boto3 amazon-sqs

我配置了一个简单的 SQS,我想一次处理 4 条消息。 在我的测试中,它有 2 个“可用”消息。当我收到消息时,一次只返回 1。我做错了什么?

Queue general configuration

sqs list

sqs = boto3.client('sqs')
response = sqs.receive_message(
    QueueUrl=queue_url,
    MaxNumberOfMessages=4
)

最佳答案

你没有做错任何事,这种行为是意料之中的。

这是由于 SQS(以及大多数 AWS 服务)的分布式特性。基本上并非所有节点都有可用的所有消息,您与之交谈的节点可能会返回 0 和 MaxNumberOfMessages 之间的任何数字(如果有的话)。要在一次调用中实际接收到多条消息,您需要在队列中有 100 条或 1000 条以上的消息,即便如此,您也可能不走运,收到的消息很少。

来自docs :

If the number of messages in the queue is small (fewer than 1,000), you most likely get fewer messages than you requested per ReceiveMessage call. If the number of messages in the queue is extremely small, you might not receive any messages in a particular ReceiveMessage response. If this happens, repeat the request.

关于python - AWS SQS ReceiveMessage 收到的消息少于请求的消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66261834/

相关文章:

amazon-web-services - 使用 MFA 登录 Azure CLI

amazon-web-services - boto3 copy vs copy_object 关于 s3 中的文件权限 ACL

pytest - 使用 moto 模拟多个 AWS 服务

hadoop - 你可以选择 boto3 s3 协议(protocol)吗?

python - 尝试创建嵌套字典时出现 KeyError

python - 获取用户角色并将其添加到 jwt 负载中

python - 如何构建azure函数python项目

amazon-web-services - 在 aws 中为前端和后端部署使用相同的域名

python - 用 python 发送电子邮件

amazon-web-services - 如何将用户数据传递到使用自定义 AMI 启动的 AWS Elastic beanstalk 实例