0

我有一个传奇:

public class MySaga : Saga<MySagaEntity>,
  IAmStartedByMessages<Message1>,
  IAmStartedByMessages<Message2> {

}

一般来说,我需要从日志中轻松查看哪些消息开始于哪个 saga。

我需要的是记录以下内容:

收到消息 Message1 with ... 开始一个新的 saga 收到消息 Message2 with ... 用于 Id=... 的现有 saga

作为替代方案,我有以下方法: 1. 如果该 saga 未启动,则检查日志文件 2. 检查 saga 的相关 ID 是否为空(以便它将在启动 saga 的处理程序中填充)

 if (Data.CorrelationId == default_value)
      _log.DebugFormat("message starts saga CorrelationId={0}", message.CorrelationId)

有谁知道更好的方法?

4

1 回答 1

1

There isn't currently a way in NServiceBus to get notified if a saga has been created or if a existing instance was loaded. (I've opened up a github issue for further discussion)

That said if the fact that the saga was created by a given message has a business meaning you're probably better off setting a boolean flag on your saga data to record this explicitly.

if(Data.SagaWasStartedByAOnlineCustomer)
    Bus.Send(new VerifySomethingForOnlineCustomersCommand);
于 2013-08-05T13:00:56.767 回答