I am dealing with nServiceBus and I want to retry and a message at another time when one fails. I have heard of Bus.Defer() but my understanding of it is limited.
I have
In your code
if (scheduleRecheck && result.ErrorMessage.Equals("Bad Request"))
{
Logger.Error("Stock query for stock code '{0}' returned a 'Product Not Found' status",
stockcode);
_bus.SendLocal<ScheduleCheckStockAvailabilityCommand>(cmd =>
{
cmd.StockCode = stockcode;
});
}
}
you are sending a message ScheduleCheckStockAvailabilityCommand. Now in your other function yoe are deferring this message i.e. ScheduleCheckStockAvailabilityCommand (which i think is called only when there is some error with CheckCurrentProductAvailabilityCommand ). So according to what I gather you want to defer CheckCurrentProductAvailabilityCommand rather than ScheduleCheckStockAvailabilityCommand so I think your code should be:
if (scheduleRecheck && result.ErrorMessage.Equals("Bad Request"))
{
Logger.Error("Stock query for stock code '{0}' returned a 'Product Not Found' status",stockcode);
_bus.Defer(_checkStockCodeAvailability.TimeOutTime, CheckCurrentProductAvailabilityCommand);
}
}