AWS SQS ReceiveMessage 收到的消息少于请求的消息?
AWS SQS ReceiveMessage receiving less / fewer messages than requested?
我配置了一个简单的 SQS,我想一次处理 4 条消息。
在我的测试中,它有 2 个“可用”消息。当我收到消息时,结果一次只有 1。我做错了什么?
sqs = boto3.client('sqs')
response = sqs.receive_message(
QueueUrl=queue_url,
MaxNumberOfMessages=4
)
您没有做错任何事,这种行为是正常的。
这是由于 SQS(以及大多数 AWS 服务)的分布式特性。基本上并非所有节点都有可用的所有消息,您与之交谈的节点可能 return 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.
我配置了一个简单的 SQS,我想一次处理 4 条消息。 在我的测试中,它有 2 个“可用”消息。当我收到消息时,结果一次只有 1。我做错了什么?
sqs = boto3.client('sqs')
response = sqs.receive_message(
QueueUrl=queue_url,
MaxNumberOfMessages=4
)
您没有做错任何事,这种行为是正常的。
这是由于 SQS(以及大多数 AWS 服务)的分布式特性。基本上并非所有节点都有可用的所有消息,您与之交谈的节点可能 return 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.