Masstransit Saga 状态机无法使用 .Net Core 中的 Azure 服务总线从消费者发送消息

问题描述 投票:0回答:1

我们正在使用 Masstransit 实现 Saga 状态机 模式。 典型的结构是我们有不同的微服务来执行数据库操作,Saga 状态机用于管理分布式事务。 我们已经通过Azure Service BUS实现了这一点。我们对事件使用**发布**方法,以便状态机可以转换到下一个状态并进一步继续。一项观察是,发布时它会创建**许多队列**,这些队列与事件类型耦合。

问题 - 我们希望减少队列数量并寻找可以与主题 - 订阅一起使用的解决方案。我们使用 Send 方法将消息发送到特定的主题订阅。 我们能够添加过滤器以确保我们可以使用特定消费者来消费消息。这种方法的问题是消费者消费后消息控制没有返回到状态机。 有没有一种方法可以将 Masstransit 与基于主题订阅的执行结合使用,该执行使用发送方法而不是发布方法。 代码的结构为 - 解决方案-

 | -- SagaStateMachine.csproj
     -- SagaStateMachineConfiguration.cs 
 | -- Order.csproj
     -- OrderRequestedConsumer.cs
     -- OrderFailedConsumer.cs
     -- OrderInitiatedConsumer.cs
     -- OrderCompletedConsumer.cs  
| -- Stock.csproj
     -- StockRequestedConsumer.cs
     -- StockFailedConsumer.cs
     -- StockInitiatedConsumer.cs
     -- StockCompletedConsumer.cs  
| -- Billing.csproj
     -- BillingRequestedConsumer.cs
     -- BillingFailedConsumer.cs
     -- BillingCompletedConsumer.cs  

执行 OrderRequestedConsumer 后,我想引发 OrderInitiatedEvent ,它需要执行 2 个操作 -

 1. Call OrderInitiatedConsumer.cs
 2. In state machine change the state and call StockRequestedEvent.cs which will be handled by StockRequestedConsumer.cs

当我使用发送方法时,状态机无法执行2个步骤

masstransit
1个回答
0
投票

以这种方式使用主题订阅并不是一个好主意,订阅不是队列并且管理起来更复杂。如果有相关的消费者,将他们放在同一个队列中。

MassTransit 在 YouTube 上有大量关于如何管理 Azure 服务总线中的拓扑的视频

© www.soinside.com 2019 - 2024. All rights reserved.