如何处理忽略的 SNS 消息

How to handle ignored SNS messages

我正在尝试使用 AWS 的 SNS 和 SQS 实施扇出架构。将有一个 FIFO 主题和几个订阅它的 FIFO 队列,每个队列都有自己的过滤策略,就像本文中一样 https://betterprogramming.pub/how-to-fan-out-to-different-sqs-queues-using-sns-message-filtering-84cd23ed9d07

在上面的文章中,他有一个我想避免的包罗万象的队列。假设我有一个主题 T 和订阅它的两个队列 Q1 和 Q2。 Q1 接受“狗”,Q2 接受“猫”。

我的问题是:

  1. 如果有人用马发布消息会怎样?
  2. 如何处理未被任何队列接收的消息? SNS DLQ最终会得到马消息还是会被丢弃?

谢谢

当消息发送到 Amazon SNS 主题时,它会发送给所有订阅者。如果队列中没有订阅者,则没有人会收到消息。

来自Amazon SNS subscription filter policies - Amazon Simple Notification Service

A subscription accepts a message under the following conditions:

  • Each attribute name in a filter policy matches an attribute name assigned to the message.

  • For each matching attribute name, at least one match exists between the following:

    • The values of the attribute name in the filter policy
    • The message attributes

因此,如果没有订阅者接受消息,则与没有订阅者相同——没有人会收到消息。

请注意,消息不会“被 SQS 队列拾取”。相反,SNS 主题将消息的副本转发给订阅者。一个订阅者是否发送消息对其他订阅者是否发送消息没有影响。

来自Amazon SNS dead-letter queues (DLQs) - Amazon Simple Notification Service

A dead-letter queue is an Amazon SQS queue that an Amazon SNS subscription can target for messages that can't be delivered to subscribers successfully. Messages that can't be delivered due to client errors or server errors are held in the dead-letter queue for further analysis or reprocessing.

因此,Amazon SNS 死信队列仅用于 传送失败 的消息。它们不用于 'messages that no subscriber wanted'.