Question

I'm planning to handle some of the business processes by use of Sagas. The end of business process may mark beginning of another instance of the same process, which I'm planning to handle through new instance of the Saga.

I have following sample code for Saga

class ProcessSaga : Saga<SProcess>,
    IAmStartedByMessages<StartProcess>,
    IHandleTimeouts<TimeToSpawn>
{
    public override void ConfigureHowToFindSaga()
    {
        ConfigureMapping<StartProcess>(e => e.ProcessId, message => message.ProcessId);
    }
    public void Handle(StartProcess message)
    {
        Data.ProcessId = message.Process.ProcessId;
        Data.Process = message.Process;
        Data.StatusTryCount = 0;

        RequestTimeout<TimeToSpawn>(DateTime.Now.AddSeconds(5));
    }

    public void Timeout(TimeToSpawn state)
    {
        var process = Data.Process;
        var startProcess = new StartProcess()
        {
            Process = new Process()
            {
                ProcessId = process.ProcessId + 100,
                ProcessName = "Long Process"
            }
        };
        Bus.Send(startProcess);
    }
}
class SProcess : IContainSagaData
{
    [Unique]
    public int ProcessId { get; set; }
    public int StatusTryCount { get; set; }
    public Process Process { get; set; }

    public Guid Id { get; set; }
    public string Originator { get; set; }
    public string OriginalMessageId { get; set; }
}

From Timeout I need to be able to create a new Saga instance by sending StartProcess message which should start new Saga, but this message is routed to the same Saga from which it was sent. What am I doing wrong and how can I implement requirements mentioned above.

Thank you

Was it helpful?

Solution

According to Andreas Ohlund (see comments to question) this was a bug in NServiceBus 4.0.2. Per his suggestion - upgraded to 4.0.3 and verified that it's working properly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top