我有一个用例,将有数据流到来,我不能以相同的速度消费它,需要一个缓冲区。这可以使用SNS-SQS队列来解决。我后来才知道,Kinesis解决了同样的目的,所以有什么不同?为什么我应该喜欢(或不应该喜欢)运动?


当前回答

另一件事:Kinesis可以触发Lambda,而SQS不能。因此,对于SQS,您要么必须提供一个EC2实例来处理SQS消息(并在失败时处理它),要么必须有一个预定的Lambda(它不能扩大或缩小—每分钟只能得到一个)。

编辑:这个答案不再正确。自2018年6月起,SQS可以直接触发Lambda

https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html

其他回答

Kinesis支持多消费者功能,这意味着相同的数据记录可以在同一时间或24小时内不同的时间在不同的消费者处处理,SQS中的类似行为可以通过写入多个队列实现,消费者可以从多个队列中读取。然而,再次写入多个队列将在系统中增加几秒(几毫秒)的延迟。

其次,Kinesis提供了路由功能,可以使用分区键将数据记录选择性地路由到不同的分片,这些分区键可以由特定的EC2实例处理,并可以启用微批处理计算{计数和聚合}。

使用任何AWS软件都很容易,但使用SQS是最简单的。使用Kinesis,需要提前提供足够的碎片,动态增加碎片数量以管理尖峰负载,并减少以节省管理所需的成本。这是运动的疼痛,SQS不需要这样的事情。SQS是无限可伸缩的。

这些技术的语义不同,因为它们是为支持不同的场景而设计的:

SNS/SQS:流中的项之间没有关联 运动:流中的项目相互关联

让我们通过例子来理解其中的区别。

Suppose we have a stream of orders, for each order we need to reserve some stock and schedule a delivery. Once this is complete, we can safely remove the item from the stream and start processing the next order. We are fully done with the previous order before we start the next one. Again, we have the same stream of orders, but now our goal is to group orders by destinations. Once we have, say, 10 orders to the same place, we want to deliver them together (delivery optimization). Now the story is different: when we get a new item from the stream, we cannot finish processing it; rather we "wait" for more items to come in order to meet our goal. Moreover, if the processor process crashes, we must "restore" the state (so no order will be lost).

一旦一个项目的处理不能与另一个项目的处理分离,我们就必须有运动语义,以便安全地处理所有的情况。

In very simple terms, and keeping costs out of the picture, the real intention of SNS-SQS are to make services loosely coupled. And this is only primary reason to use SQS where the order of the msgs are not so important and where you have more control of the messages. If you want a pattern of job queue using an SQS is again much better. Kinesis shouldn't be used be used in such cases because it is difficult to remove messages from kinesis because kinesis replays the whole batch on error. You can also use SQS as a dead letter queue for more control. With kinesis all these are possible but unheard of unless you are really critical of SQS.

如果你想要一个好的分区,那么SQS将不会有用。

请记住,这个答案在2015年6月是正确的

在研究了这个问题一段时间后,我心里有同样的问题,我发现SQS(带SNS)是大多数用例的首选,除非消息的顺序对您很重要(SQS不保证消息的FIFO)。

Kinesis有2个主要优势:

您可以从多个应用程序读取相同的消息 如果需要的话,您可以重新阅读邮件。

这两个优点都可以通过使用SNS作为SQS的扇出来实现。这意味着消息的生产者只向SNS发送一条消息,然后SNS将消息分散到多个SQSs,每个使用者应用程序一个SQSs。通过这种方式,您可以拥有尽可能多的消费者,而无需考虑分片容量。

此外,我们还增加了一个订阅SNS的SQS,可以保存14天的消息。在正常情况下,没有人从这个SQS中读取数据,但如果出现让我们想要倒带数据的错误,我们可以轻松地从这个SQS中读取所有消息,并将它们重新发送到SNS。而Kinesis仅提供7天的留存。

总之,SNS+SQSs更简单,提供了大部分功能。在我看来,你需要一个非常有力的案例来选择Kinesis。

对我来说,最大的优势是Kinesis是一个可重玩的队列,而SQS不是。因此,您可以有多个Kinesis的相同消息的消费者(或在不同时间的相同消费者),而在SQS中,一旦消息被ack,它就从队列中消失了。 因此,SQS更适合工作者队列。