Saga- Can we used the same saga if we received start message multiple times, if its not closed. and if its already closed then create new saga

Saga - If IAmStartedByMessages message received saga started and before closing the saga again if we received the same message with same contextid, then i have to use the existing saga for some operation.

How can we handle this.

Ex -

public class AddEmployeeSaga : Saga,
IAmStartedByMessages,
IHandleMessages
{
}

If INewEmployeeReceived first time, then saga is started and before closing the saga. If we received same INewEmployeeReceived for same employeeId, then i have to use existing saga and continue processing.

How can we achieve this.

Hi @VinodBhoite,

Assuming that INewEmployeeReceived is the message/event starting the Saga and the contextid is the Saga instance correlation you don’t have to do any special thing. Saga concurrency behavior ensures that only one message starts the saga. The second message will be retry because of optimistic concurrency and in the second processing attempt the previous created Saga instance will be found.

You can find more details about Saga concurrency in the docs -> https://docs.particular.net/nservicebus/sagas/concurrency There is special section about starting the Saga -> https://docs.particular.net/nservicebus/sagas/concurrency#starting-a-saga

You can also find Saga concurrency information on the concrete Persistence section for example for SQL Persistence -> https://docs.particular.net/persistence/sql/saga-concurrency

Hope this help.

… but could you specify what does this mean closing the Saga? The end of Saga processing or mark Saga as complete or something else?