Reputation: 97
My scenario is, that when a service order is created the NServiceBus saga should keep on looking for daily pending dues. If dues are available it should sendlocal message to the payment handler. I am continuously using a while loop to check the dues and send a delay message to the payment handler with 20min delay. I am using Azure ServiceBus to send/receive messages.
The problem is the payment handler not receiving the messages. The application is also consuming more memory and the application gets stuck after some time.
Can you suggest an idea to fix this? Thanks in advance!
while (!Data.IsAllPaymentsDone)
{
var paymentRequest = new StartPaymentCommand()
{
OrderId = message.OrderId,
CompanyId = message.CompanyId,
ItemNumber = message.ItemNumber,
DueAmount = message.DueAmount
};
var options = new SendOptions();
options.RouteToThisEndpoint();
options.DelayDeliveryWith(TimeSpan.FromSeconds(Convert.ToInt32(TimeInSeconds))); // 20min delay
await context.Send(paymentOrchestrationRequest, options);
}
Upvotes: 0
Views: 157
Reputation: 25994
A saga is a process coordinator. It shouldn't do active work or run continuously, as your while
loop does. If you need periodic execution of a saga to to occur for a compensation action(s), use timeouts.
You'll need to update your design.
Upvotes: 3