简体   繁体   English

SQS队列/可见性超时/消息组

[英]SQS Queues/ Visibility Timeouts/ message groups

I am new to AWS. 我是AWS的新手。 I am trying to understand SQS here. 我想在这里了解SQS。 I have gone over a few trainings also but I still could not get some answers there in the discussion forum. 我也参加了一些培训,但我仍然无法在讨论论坛上得到一些答案。 I am re-iterating my question here. 我在这里重复我的问题。 Note that I know that a few questions below have obvious answers and are therefore more of a rhetoric. 请注意,我知道下面的一些问题有明显的答案,因此更多的是一种修辞。 My confusion stems from the fact that my understanding of the topic at present leads me to give conflicting answers to the follow up questions that spring up in my mind after the obvious known ones and takes away the confidence of whatever I think I understand alright. 我的困惑源于这样一个事实,即我对这个主题的理解使我对那些在明显已知的问题之后出现在我脑海中的后续问题给出了相互矛盾的答案,并且消除了我认为我理解的任何事情的信心。

If I have a Standard queue named MyQueue and there are 100 messages, and if there are 2 completely separate applications (as consumers; note they are not a consumer group of the same applications like you have in Kafka; instead they are 2 separate applications) for this queue, then the consumers may receive 如果我有一个名为MyQueue标准队列并且有100条消息,并且有2个完全独立的应用程序(作为消费者;请注意它们不是像Kafka中那样的相同应用程序的消费者组;相反,它们是2个单独的应用程序)对于这个队列,消费者可能会收到

(i) out of order messages and (i)无序消息和

(ii) multiple copies of the messages (ii)消息的多个副本

Both of my applications do not need to bother about the order of the messages. 我的两个应用程序都不需要打扰消息的顺序。 But for the sake of the question lets say we have a perfect order of delivery, no multiple copies and no network issues and both consumers finish their processing if each message well within the Visibility Timeout window. 但是为了这个问题,我们可以说我们有一个完美的交付顺序,没有多个副本,也没有网络问题,如果每个消息都在Visibility Timeout窗口内,消费者都会完成处理。

Q1: Will both the applications individually receive 100 messages each or will a message that is made available to one consumer won't ever be delivered to the other consumer? 问题1:两个应用程序是否各自单独收到100条消息,或者一条消费者可用的消息是否永远不会传递给其他消费者? If the latter is true ( with no network issues, out of order delivery, multiple deliveries), then: 如果后者是真的(没有网络问题,无序交付,多次交付),那么:

  1. Is SNS-SQS fanout the way to ensure that the same message is processed by multiple consumers? SNS-SQS是否能够确保多个消费者处理相同的消息?
  2. Is the consumer supposed to delete the message from the queue after processing? 消费者是否应该在处理后从队列中删除消息? So, if a message is picked up by a processor, and it goes into visibility timeout while the processing happens and then is not deleted by the consumer even after the processing is complete before the visibility timeout, then will the message appear back for other consumers possibly to consume it? 因此,如果处理器拾取了一条消息,并且在处理发生时它进入可见性超时,即使在可见性超时之前处理完成之后消费者也不会删除该消息,那么该消息将显示给其他消费者可能要消耗它? If that is the case, then won't the same thing apply to a FIFO queue as well? 如果是这种情况,那么同样的事情也不适用于FIFO队列吗?

Other Questions: 其他问题:

Q2: Is the Visibility timeout applicable to both Standard Queue and FIFO Queue? Q2:可见性超时是否适用于标准队列和FIFO队列? If it is also applicable to FIFO Queue which promises exactly once delivery, then, if the Visibility Timeout appears before the consumer ends processing a message, then it reappears in the queue only to be delivered again thereby going back to at least once processing. 如果它也适用于一次传递承诺的FIFO队列,那么,如果在消费者结束处理消息之前出现可见性超时,则它再次出现在队列中以便再次传递,从而返回至少一次处理。 Can someone confirm? 有人可以证实吗?

Q3: What are multiple message Groups within a FIFO Queue? 问题3: FIFO队列中的多个消息组是什么? Are they like partitions of a queue? 他们喜欢队列的分区吗?

Q: Will both the applications individually receive 100 messages each? 问:两个应用程序是否各自单独收到100条消息?

A consumer can request up to 10 messages per API call. 消费者可以为每个API调用请求最多10条消息。 These will become 'invisible' and will not be provided to other consumers. 这些将变为“隐形”, 不会提供给其他消费者。 (Well, there actually is a small possibility that a message might be provided to multiple consumers. It is rare, but it can happen. If this is bad for your use-case, then you should track the messages in a database to ensure they are only processed once each.) (嗯,实际上可能会向多个消费者提供消息。这很少见,但可能会发生。如果这对您的用例不利,那么您应该跟踪数据库中的消息以确保它们每个只处理一次。)

Q: Is SNS-SQS fanout the way to ensure that the same message is processed by multiple consumers? 问:SNS-SQS是否能够确保多个消费者处理相同的消息?

It is very strange to want to want a single message consumed by 'multiple consumers'. 想要“多个消费者”消费的单个消息是非常奇怪的。 The normal desire is to process each message once. 通常的愿望是处理每个消息一次。 If you do want a message processed by multiple consumers then, yes, you could send the message to SNS, which could then send it to multiple queues. 如果你确实想要一个由多个消费者处理的消息,那么,是的,你可以将消息发送给SNS,然后SNS可以将它发送到多个队列。

Q:Is the consumer supposed to delete the message from the queue after processing? 问:消费者是否应该在处理后从队列中删除消息?

Yes. 是。 Amazon SQS does not know when a message is processed. Amazon SQS不知道何时处理消息。 The consumer must delete the message via the ReceiptHandle provided when the message was received. 消费者必须通过收到消息时提供的ReceiptHandle删除消息。 If a message times-out and another consumer receives it, SQS will provide a different ReceiptHandle so it knows which process requested the delete. 如果消息超时且另一个消费者收到消息,则SQS将提供不同的 ReceiptHandle,以便它知道哪个进程请求删除。

This also applies to FIFO queues. 这也适用于FIFO队列。

Q: Is the Visibility timeout applicable to both Standard Queue and FIFO Queue? 问:可见性超时是否适用于标准队列和FIFO队列?

Yes. 是。 If the visibility timeout expires, the message will be provided to another consumer. 如果可见性超时到期,则将消息提供给另一个消费者。 The "exactly once delivery" avoids the rare situation mentioned above when a message in a Standard queue might be provided more than once. 当“标准队列”中的消息可能被多次提供时,“恰好一次传送”可以避免上述罕见情况。 However, if visibility times-out, even in a FIFO queue, then it will intentionally be visible on the queue again. 但是,如果可见性超时,即使在FIFO队列中,也会故意在队列中再次显示。

Q: What are multiple message Groups within a FIFO Queue? 问:FIFO队列中的多个消息组是什么? Are they like partitions of a queue? 他们喜欢队列的分区吗?

A message group is a way of grouping messages that must be delivered in-order. 消息组是一种对必须按顺序传递的消息进行分组的方法。

Let's say there are two message groups, A and B , and they send messages in this order: A1 , B1 , A2 , B2 假设有两个消息组AB ,它们按以下顺序发送消息: A1B1A2B2

Message B1 can be provided even if A1 is not yet deleted. 即使A1尚未删除,也可以提供消息B1 However, message A2 will not be provided until A1 is deleted. 但是,在删除A1之前, 不会提供消息A2 Think of them as 'mini-queues'. 把它们想象成“迷你队列”。 This allows processing of lots of messages are are unrelated, without having to wait for all previous messages to be deleted. 这允许处理大量消息是不相关的,而不必等待删除所有先前的消息。

See: Using the Amazon SQS Message Group ID - Amazon Simple Queue Service 请参阅: 使用Amazon SQS消息组ID - Amazon Simple Queue Service

Q1: Will both the applications individually receive 100 messages each or will a message that is made available to one consumer won't ever be delivered to the other consumer? 问题1:两个应用程序是否各自单独收到100条消息,或者一条消费者可用的消息是否永远不会传递给其他消费者?

Neither of these is quite accurate. 这些都不是很准确。

Standard queues never intentionally deliver a message more than once. 标准队列从不故意多次传递消息。 It is possible that messages may occasionally be delivered more than once -- but this is the exception and is an artifact of the fact that SQS is a distributed system and situations could arise where, for example, the queue had a message stored in multiple replicas and the fact that a message was not known to all replicas due to an internal failure. 有时可能多次传递消息 - 但这是例外情况,并且是SQS是分布式系统这一事实的假象,并且可能出现这样的情况:例如,队列在多个副本中存储了消息以及由于内部故障而导致所有副本都不知道消息的事实。

If a message is inadvertently delivered more than once, it could be to multiple consumers or the same consumer. 如果消息无意中被多次传递,则可能是多个消费者或同一个消费者。 The consumer "connections" to SQS are actually stateless, resetting each time a list of messages is delivered, so SQS does not have a sense of which consumer it delivered each message to. 消费者与SQS的“连接”实际上是无状态的,每次传递消息列表时都会重置,因此SQS无法了解每个消息传递给哪个消费者。

Consumers delete their messages after processing, otherwise their visibilitt timeout expires and they are delivered again and again -- to whichever consumer the luck of the draw delivers them to, each time. 消费者在处理后删除他们的消息,否则他们的可见时间超时并且他们一次又一次地被递送 - 每次都是抽奖运气给他们的消费者。 As noted, SQS has no concept of consumer identity or state. 如上所述,SQS没有消费者身份或国家的概念。 (In high volume applications, a single consumer may actually have multiple connections to SQS, all receiving messages in parallel, because the network round-trips and cycle of receive/delete will otherwise limit a single consumer to a few hundred messages per second. Whether these connections are handled using asynchronous I/O, threads, etc., is unimportant to SQS, which doesn't care which consumer is on a given connection.) (在大批量应用中,单个消费者实际上可能有多个与SQS的连接,所有人都并行接收消息,因为网络往返和接收/删除周期将限制单个消费者每秒几百条消息。使用异步I / O,线程等处理这些连接对于SQS并不重要,因为SQS不关心给定连接上的哪个消费者。)

If you want all messages sent to all consumers, you need fan-out from SNS to SQS. 如果您希望将所有消息发送给所有消费者,则需要从SNS扇出到SQS。

Q2: Is the Visibility timeout applicable to both Standard Queue and FIFO Queue? Q2:可见性超时是否适用于标准队列和FIFO队列?

Yes. 是。 Because (noted above) the connection to SQS is not a persistent, stateful connection, SQS uses visibility timeout as the indication that a consumer has lost the message or failed ungracefully, so the message needs to be made accessible again. 因为(如上所述)与SQS的连接不是持久的有状态连接,SQS使用可见性超时作为消费者丢失消息或失败失败的指示,因此需要再次访问消息。 (Dead letter queues prevent this from happening endlessly, moving a message to a different queue, since repeated failures indicate a problem with a consumer, or a "poison pill" message.) (死信队列阻止这种情况无休止地发生,将消息移动到不同的队列,因为重复的故障表明消费者有问题,或者是“毒丸”消息。)

FIFO queues retain in-order delivery, here, and you could argue that they revert to "at least once" delivery, but the idea is that this should never happen. FIFO队列保留了按顺序交付,在这里,您可以争辩说它们会恢复到“至少一次”交付,但我们的想法是永远不会发生这种情况。 If it does, then your visibility timeout is too short or your consumer is crashing or otherwise misplacing messages. 如果是这样,那么您的可见性超时太短或者您的消费者正在崩溃或以其他方式错误地放置消息。

Q3: What are multiple message Groups within a FIFO Queue? 问题3:FIFO队列中的多个消息组是什么?

Message groups allow FIFO queues to support in-order, parallel processing of groups messages whose ordering relative to each other across group boundaries doesn't matter. 消息组允许FIFO队列支持按顺序并行处理组消息,这些消息在组边界上相对于彼此的排序无关紧要。 Messages are delivered in order, within each group. 消息按顺序在每个组内传递。

If a FIFO queue, if all messages are sent with the same group ID, then only one consumer can be working at a time. 如果是FIFO队列,如果所有消息都使用相同的组ID发送,则一次只能有一个消费者工作。

In-order delivery (simple illustration) means that message 2 will not be delivered to any consumer until message 1 has been received and deleted -- finished -- by a consumer. 按顺序传送(简单说明)意味着消息2将不被传送给任何消费者,直到消息1被消费者接收并删除 - 完成。 In order delivery includes all processing (not merely the initial "delivery"). 订单交付包括所有处理 (不仅仅是初始“交付”)。 Or if 20 messages in the queue have the same group ID and two consumers request 10 messages each, one consumer gets 10 and the other gets nothing -- yet -- because those second 10 messages have to be sequestered, until the first 10 have been processed (else we are no longer "in order"). 或者如果队列中的20个消息具有相同的组ID,并且两个消费者每个请求10个消息,则一个消费者获得10个消息而另一个消费者什么都没有 - 但是 - 因为那些后10个消息必须被隔离,直到前10个消息已经被隔离已处理(否则我们不再“按顺序”)。

In the 20 messages scenario, if 14 were in group A and 6 were in group B, one consumer would receive A1-A10, A11-A14 would be sequestered until A1-A10 were complete, but while the first consumer is busy, another consumer could have B1-B6 at the same time. 在20个消息场景中,如果14个在A组,6个在B组,一个消费者将获得A1-A10,A11-A14将被隔离,直到A1-A10完成,但是当第一个消费者忙,另一个消费者可以同时拥有B1-B6。

Note again that there is no consumer affinity. 再次注意,没有消费者亲和力。 If A1-A10 and B1-B6 were deleted at the same instant, A11-A14 would next be delivered to one consumer, but not necessarily the one that handled A1-A10. 如果在同一时刻删除A1-A10和B1-B6,则接下来将A11-A14交付给一个消费者,但不一定是处理A1-A10的消费者。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM