AWS SQS + Lambda消息在Lambda处理程序中记录数组的顺序。

huangapple go评论65阅读模式
英文:

AWS SQS + lambda message order in lambda handler records array

问题

我计划在我的应用程序中使用AWS SQS FIFO队列,该队列从SNS FIFO主题获取消息。队列以先进先出的顺序提供消息。根据文档,对我不太清楚的是,当从队列接收消息批次时,Records数组的排序是什么意思。

在该数组中,具有最高索引号的项目是否是通过SNS+SQS发送的第一个项目?而具有最低索引号的是最新的项目吗?这是我根据第一个从数组中弹出的项目的逻辑来猜测的。当您调用数组的pop时,会获取具有最高索引号的项目。因此,这将是“第一个出去”的项目。或者,如果我通过forEach从数组的开头循环遍历数组,我会首先获取到最新的消息吗?

我只是在文档中没有找到这方面的确认,我的测试消息的消息元数据上的时间相同,这是由于批处理和它们通过SNS的速度很快。消息上还有一个SequenceNumber,对于具有较高索引号的项目,该值较高,我不确定该如何解释。

英文:

I'm planning to use an AWS SQS FIFO queue with my application, which queue gets messages from an SNS FIFO topic. The queue provides the messages in first-in-first-out order. What is not very clear to me by documentation is what does this mean for the ordering of the Records array provided to the lambda's handler function when receiving batches of messages from the queue.

Is the item in that array with the highest index number the first item that was sent through SNS+SQS? And the lowest index number is the newest item? This would be my guess based on the logic the first item off the array would be the one you get when you call pop on the array. You get the item with the highest index number. So this would be the "first out" item. Or if I loop through the array from the start of the array with forEach, I get the newest message first?

I just didn't find confirmation for this in docs and the times on the message metadata for my test messages are the same due to batching and how fast they go through SNS. There is also a SequenceNumber on the messages which is higher for the item with the higher index number, which I'm not sure what to make of.

答案1

得分: 0

我测试过这个。从SQS FIFO队列中,事件以如下顺序提供给Lambda,在Lambda处理函数的参数中以Records数组的形式,使得“先进先出”的项目是具有最低索引号的项目,因此数组是[最旧的,较新的,最新的]。我想这是有道理的,只是需要确认一下。

英文:

I tested this. From an SQS FIFO queue the events are provided to lambda in the Records array in the lambda handler function argument in such order that the "first in" item is the one that has the lowest index number so the array is [oldest, newer, newest]. I guess that makes sense, just needed to be sure.

huangapple
  • 本文由 发表于 2023年5月11日 19:18:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/76227055.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定