考题解析 | 使用 Amazon SQS 提供解耦解决方案


  题目

A company has an application that ingests incoming messages. Dozens of other applications and microservices then quickly consume these messages. The number of messages varies drastically and sometimes increases suddenly to 100,000 each second. The company wants to decouple the solution and increase scalability.
Which solution meets these requirements?
A. Persist the messages to Amazon Kinesis Data Analytics. Configure the consumer applications to read and process the messages.
B. Deploy the ingestion application on Amazon EC2 instances in an Auto Scaling group to scale the number of EC2 instances based on CPU metrics.
C. Write the messages to Amazon Kinesis Data Streams with a single shard. Use an AWS Lambda function to preprocess messages and store them in Amazon DynamoDB. Configure the consumer applications to read from DynamoDB to process the messages.
D. Publish the messages to an Amazon Simple Notification Service (Amazon SNS) topic with multiple Amazon Simple Queue Service (Amazon SOS) subscriptions. Configure the consumer applications to process the messages from the queues.

  参考答案

D

  参考解析

技巧:排除明显错误选项,在没有明显错误的选项中选择最合理的选项。
某公司有一个应用程序负责接收消息,有数十个其他应用程序和微服务应用都需要迅速消费这些消息。消息的数量变化很大,有时会突然增加到每秒10万条。公司希望解耦解决方案并提高可扩展性。

A. 不正确。使用 Amazon Kinesis Data Analytics。Amazon Kinesis Data Analytics 主要用于实时分析数据流,而不是作为消息队列或消息中间件。它不适合直接用于消息的持久化和消费。
B. 不正确。在Auto Scaling组中的Amazon EC2实例上部署应用程序。Auto Scaling 可以根据CPU 指标自动调整 EC2 实例的数量,但这主要解决的是计算资源的弹性伸缩问题,而不是消息传递和消费的问题。此外,这种方法并没有实现消息系统的解耦。
C. 不正确。使用 Amazon Kinesis Data Streams 和单个分片。使用Amazon Kinesis Data Streams 是一个消息流服务,但使用单个分片是不合适的。因为 Kinesis Data Streams 的每个分片有一个每秒1 MB的输入限制和每秒2 MB的输出限制(对于增强型分片,这些限制更高,但单个分片仍然不足以处理每秒10万条消息的高负载)。此外,虽然Lambda函数可以用于预处理消息并将其存储在DynamoDB中,但这种方法增加了系统的复杂性和延迟。
D. 正确。使用 Amazon SNS和多个 Amazon SQS 订阅。Amazon SNS(简单通知服务)是一个高度可扩展的、灵活的发布/订阅消息传递服务。它允许将消息发送到多个订阅者,这些订阅者可以是SQS队列、HTTP/HTTPS端点、Lambda函数等。在这个场景中,使用SNS发布消息,并让多个SQS队列订阅这些消息是合适的。每个消费者应用程序可以从其专用的SQS队列中读取消息进行处理,这样实现了消息的解耦和可扩展性。此外,SQS队列可以自动扩展以处理任意数量的消息,无需人工干预。