我有两个传奇,即客户传奇和客户计费传奇。
public class ClientSagaState:IContainSagaData
{
#region NserviceBus
public Guid Id { get; set; }
public string Originator { get; set; }
public string OriginalMessageId { get; set; }
#endregion
public Guid ClientRef { get; set; }
public ClientMessage ClientChangeMessage { get; set; }
public ClientContactChangeMessage ClientContactChange { get; set; }
}
public class ClientBillingSagaState:IContainSagaData
{
#region NserviceBus
public Guid Id { get; set; }
public string Originator { get; set; }
public string OriginalMessageId { get; set; }
#endregion
public Guid ClientRef { get; set; }
public Guid FunderRef { get; set; }
public Guid ClientBillingRef { get; set; }
public ClientBillingMessage ClientBillingMessage { get; set; }
}
public class ClientSaga:Saga<ClientSagaState>,
IAmStartedByMessages<ClientChangeMessage>,
IAmStartedByMessages<ClientContactChangeMessage>
{
public override void ConfigureHowToFindSaga()
{
ConfigureMapping<ClientChangeMessage>(s => s.ClientRef, m => m.EntityRef);
ConfigureMapping<ClientContactChangeMessage>(s => s.ClientRef, m => m.PrimaryEntityRef);
}
public void Handle(ServiceUserChangeMessage message)
{
if (BusRefTranslator.GetLocalRef(EntityTranslationNames.ClientChange, message.EntityRef.Value) != null)
{
GetHandler<ClientChangeMessage>().Handle(message);
CompleteTheSaga();
return;
}
HandleServiceUserChangeAndDependencies(message);
//MarkAsComplete();
CompleteTheSaga();
}
}
public class ClientBillingSaga:Saga<ClientBillingSagaState>
,IHandleMessages<ClientChangeMessage>,
IAmStartedByMessages<ClientBillingMessage>,
IHandleMessages<FunderChangeMessage>
{
public override void ConfigureHowToFindSaga()
{
ConfigureMapping<ClientChangeMessage>(s => s.ClientRef, m => m.EntityRef);
ConfigureMapping<FunderChangeMessage>(s => s.FunderRef, m => m.EntityRef);
ConfigureMapping<ClientBillingMessage>(s => s.ClientBillingRef, m => m.PrimaryEntityRef);
}
public void Handle(ClientChangeMessage message)
{
var state = this.Data;
if (state.ClientBillingMessage != null)
{
Handle(state.ClientBillingMessage);
}
}
public void Handle(CareSysInvoiceLineInsertMessage message)
{
//First check for the funder
//If funder is not there store the message in saga
//If funder is there then check for client
//If client is not there then put the message in saga
// if funder and client are there then execute the message delete the saga
}
}
这是场景:
1)如果我收到一个客户和资助者不存在的 ClientBillingMessage,我将此消息存储在 saga 中。
2)如果现在出资者消息来了,那么它就会被执行,但是传奇仍然存在,因为它正在等待客户消息
3)现在,如果客户端消息来了,它首先运行 ClientBillingSaga 的客户端消息处理程序,因此已经存在的 ClientBillingSaga 仍然存在,然后它继续执行 ClientSaga 中的处理程序以获取客户端消息。
我的问题:有什么办法可以命令执行这两个传奇。我找到了处理消息处理的 ISpecifyMessageHandlerOrdering 接口,但我认为我不能将它用于传奇。