Azure 服务总线按顺序处理消息

Azure Service Bus ordered processing of message

如果对于 Azure 服务总线主题,存在具有某些筛选器的单个订阅。有一个微服务 A 为订阅创建了一个 SubscriptionClient,并发为 1 以读取消息。此外,如果此服务 A 有 2 个这样的副本,并且假设在 unpartitioned 服务总线主题中有 3 条消息在 t1、t2 和 t3 时间插入到主题。

t1 < t2 < t3

  1. t2 消息是否有可能在 t1 传递到 Replica-1 之前通过服务总线传递到 Replica-2?

  2. 如果不是,在处理订阅和添加消费微服务的副本时,服务总线主题的扩展策略是什么。

注:与kafka相比,它确保1个分区的消息只传递给一个副本和一个正在监听该分区的线程,从而有序处理消息是有保证的。但不确定 w.r.t 服务总线主题,如 Azure 服务总线,如果多个副本正在侦听具有不同订阅客户端的同一订阅,它们是否会 receive/process 乱序消息?

如果要使用 Azure 服务总线启用有序消息处理,则必须使用 Sessions.

您可以使用消息的 SessionId 作为您在 Kafka 中使用的 partitionId 的等价物。这样,您仍然可以扩展您的消费者,在任何给定时间受不同 SessionId 值的数量限制。

Message sessions. Implement workflows that require message ordering or message deferral.

Sessions provide concurrent de-multiplexing of interleaved message streams while preserving and guaranteeing ordered delivery.

When multiple concurrent receivers pull from the queue, the messages belonging to a particular session are dispatched to the specific receiver that currently holds the lock for that session. With that operation, an interleaved message stream in one queue or subscription is cleanly de-multiplexed to different receivers and those receivers can also live on different client machines, since the lock management happens service-side, inside Service Bus.

服务总线 Partitions 将负载分散到多个节点,并且不提供任何顺序保证。

Partitioning means that the overall throughput of a partitioned entity is no longer limited by the performance of a single message broker or messaging store. In addition, a temporary outage of a messaging store does not render a partitioned queue or topic unavailable.