考题解析 | 使用 Amazon SQS FIFO 队列确保消息顺序


  题目

A company is building an e-commerce web application on AWS. The application sends information about new orders to an Amazon API Gateway REST API to process. The company wants to ensure that orders are processed in the order that they are received.
Which solution will meet these requirements?
A. Use an API Gateway integration to publish a message to an Amazon Simple Notification Service (Amazon SNS) topic when the application receives an order. Subscribe an AWS Lambda function to the topic to perform processing.
B. Use an API Gateway integration to send a message to an Amazon Simple Queue Service (Amazon SQS) FIFO queue when the application receives an order. Configure the SQS FIFO queue to invoke an AWS Lambda function for processing.
C. Use an API Gateway authorizer to block any requests while the application processes an order.
D. Use an API Gateway integration to send a message to an Amazon Simple Queue Service (Amazon SQS) standard queue when the application receives an order. Configure the SQS standard queue to invoke an AWS Lambda function for processing.

  参考答案

B

  参考解析

技巧:排除明显错误选项,在没有明显错误的选项中选择最合理的选项。
某公司正在AWS 上构建电子商务web应用程序处理订单系统,需要确保订单按照接收的顺序进行处理,需要选择一个合适的AWS服务组合。

A. 不正确。使用 API Gateway 集成将消息发布到 Amazon Simple Notification Service (Amazon SNS)主题,并订阅一个 AWS Lambda 函数来处理。SNS 主题主要用于发布/订阅消息模型,它并不保证消息的顺序。因此,这个选项不适合需要保持消息顺序的场景。
B. 正确。使用 API Gateway 集成将消息发送到 Amazon Simple Queue Service (Amazon SQS) FIFO 队列,并配置 SQS FIFO 队列来调用AWS Lambda函数进行处理。SQS FIFO(First-In-First-Out)队列正是为了保持消息的顺序而设计的。这意味着消息会严格按照它们被发送的顺序被处理。此外,SQS FIFO可以配置为自动触发Lambda函数,从而满足自动处理订单的需求。
C. 不正确。使用 API Gateway 授权器来阻塞任何请求,直到应用程序处理完一个订单。该方案并不实用,因为它会阻塞新的订单请求,直到前一个订单被处理完毕。这不仅降低了系统的吞吐量,而且在实际应用中很难实现,因为它需要实时跟踪订单的处理状态。
D. 不正确。使用 API Gateway 集成将消息发送到 Amazon Simple Queue Service (Amazon SQS) 标准队列,并配置 SQS 标准队列来调用 AWS Lambda 函数进行处理。SQS标准队列不保证消息的顺序。在负载较高的情况下,消息可能会乱序处理。