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


当前回答

Kinesis解决了流数据典型的映射缩减场景中的映射部分问题。而SQS并不确定这一点。如果你有需要在一个键上聚合的流数据,kinesis可以确保该键的所有数据都到一个特定的分片,并且该分片可以在单个主机上使用,这使得在键上的聚合比SQS更容易

其他回答

从表面上看,它们有点相似,但是用例将决定哪种工具是合适的。在我看来,如果你可以使用SQS,那么你应该——如果它能做你想做的事情,它会更简单、更便宜,但这里有一个来自AWS FAQ的更好解释,它给出了两个工具的适当用例示例,以帮助你决定:

常见问题的

Kinesis解决了流数据典型的映射缩减场景中的映射部分问题。而SQS并不确定这一点。如果你有需要在一个键上聚合的流数据,kinesis可以确保该键的所有数据都到一个特定的分片,并且该分片可以在单个主机上使用,这使得在键上的聚合比SQS更容易

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

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

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

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将不会有用。

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

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).

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