2

我希望有人可以帮助我解决我的问题,因为我已经疯狂地用谷歌搜索它,但没有结果。

我正在尝试在 NServicebus 中实现一个传奇。saga 中的 handle 方法使用 bus.Send() 方法通过总线调用两个不同的处理程序(参见下面的代码)。然后,当每个处理程序完成其工作时,它会以相同的方式将通知消息发送回 saga。saga 检查其状态并在所有步骤完成后调用 MarkAsComplete()。在这个传奇中,我使用一个消息队列和端点进行所有通信。

在到达方法 public void Handle(Notify1DataMessage message) 和 public void Handle(Notify2DataMessage message) 之前,每个处理程序都会收到以下两条警告行:


警告:找不到 ID [GUID] 的消息类型 Notify1Message 的 saga。将调用 SagaNotFoundHandlers。

警告:NServiceBus.Sagas.SagaPersistenceBehavior:找不到消息类型命名空间的传奇。Notify1Message 与 id [GUID]。将调用 SagaNotFoundHandlers。


我究竟做错了什么?一切正常,它在 saga 中找到了通知句柄方法,但为什么会抱怨?

相关代码:

public class RemovalSaga : Saga<SomeSagaData>,
                           IAmStartedByMessages<RemoveDataMessage>,
                           IHandleMessages<Notify1DataMessage>,
                           IHandleMessages<Notify2DataMessage>
{
    // The mapping uses a string property called QueueMessage that is unique
    public override void ConfigureHowToFindSaga()
    {
        ConfigureMapping<RemoveDataMessage>(m => m.QueueMessage).ToSaga(saga => saga.QueueMessage);
        ConfigureMapping<Notify1DataMessage>(m => m.QueueMessage).ToSaga(saga => saga.QueueMessage);
        ConfigureMapping<Notify2DataMessage>(m => m.QueueMessage).ToSaga(saga => saga.QueueMessage);
    }

    public void Handle(RemoveDataMessage message)
    {       
        Data.QueueMessage = message.QueueMessage;
        //...
        var message1 = new Handler1DataMessage
        {
            QueueMessage = Data.QueueMessage
        };
        _bus.Send(message1);

        var message2 = new Handler2DataMessage
        {
            QueueMessage = Data.QueueMessage
        };
        _bus.Send(message2);
    }

    // The warning fires just before this Handle method is reached.
    public void Handle(Notify1DataMessage message)
    {
        if (!Data.AllStepsDone) return;
        MarkAsComplete();
    }

    // The warning fires just before this Handle method is reached.
    public void Handle(Notify2DataMessage message)
    {
        if (!Data.AllStepsDone) return;
        MarkAsComplete();
    }
}



//Both handlers have the same relevant code (showing one of them):
public class Handler1 : IHandleMessages<Handler1DataMessage>
    //...
    public void Handle(Handler1DataMessage message)
    {
        //...
        var notifyMessage = new Notify1DataMessage
        {
            QueueMessage = message.QueueMessage
        };
        _bus.Send(notifyMessage);
    }
}



//Endpoint configuration:
public class EndpointConfig : IConfigureThisEndpoint, AsA_Server, IWantCustomInitialization
{
    public void Init()
    {
        //...
        Configure.Features.Enable<Sagas>();
        Configure.With()        
            .LicensePath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "License\\License.xml"))
            .NinjectBuilder(kernel)
            .UseTransport<Msmq>()
            .RavenPersistence()
            .RavenSagaPersister()
            .UnicastBus()
            .LoadMessageHandlers()
            .UseRavenTimeoutPersister();
    }
}


//SomeSagaData just in case:
public class SomeSagaData : IContainSagaData
{
    [Unique]
    public virtual string QueueMessage { get; set; }

    public virtual Guid Id { get; set; }
    public virtual string Originator { get; set; }
    public virtual string OriginalMessageId { get; set; }
    //...
}
4

0 回答 0