NServiceBus TimeOut Manager

I developed an example application for checking timeout control in a saga using NserviceBus.

I am trying to achieve the following

When the saga started to set the timeout to 1 minute before the timeout expires, if the update came to the update, the timeout update to 5 minutes My code looks below

public class OrderSaga : Saga<OrderSagaData>, IAmStartedByMessages<SampleMessage>, IHandleMessages<UpdateMessage> { public override void ConfigureHowToFindSaga() { ConfigureMapping<UpdateMessage>(s => s.PurchaseOrderNumber, m => m.Update); } public void Handle(SampleMessage message) { this.Data.PurchaseOrderNumber = message.Name; RequestTimeout(DateTime.Now.AddMinutes(1), message.Name); } private void Complete() { MarkAsComplete(); } public override void Timeout(object state) { Complete(); } #region IMessageHandler<UpdateMessage> Members public void Handle(UpdateMessage message) { this.Data.PurchaseOrderNumber = message.NewValue; RequestTimeout(DateTime.Now.AddMinutes(5), message.Update); } #endregion } } 

But the problem here is that the timeout is not updated to 5 minutes. The timeout is still running for 1 minute.

Could you tell me what is being done wrong here?

Thanks in advance, Ajay

+4
source share
1 answer

Saga timeouts cannot be updated. They will shoot no matter what you do. In your case, you will receive both timeouts and, if you call “Full” in your timeout handler, your saga will end in one minute. You need to add some logic that takes this into account.

Something like this might do this:

  if (! updateReceived or state == ThisTimeoutWasRequestedByMyUpdateHandler)
    Complete ();

Hope this helps!

+4
source

Source: https://habr.com/ru/post/1336089/


All Articles