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 a system that checks stock codes. It checks when the command is called and reschedules another check after 8pm.
I have CheckCurrentProductAvailabilityCommand that runs a function that checks stock codes. This is handled by CurrentProductAvailabilityRequestHandler.
If it fails I then run ScheduleCheckStockAvailabilityCommand with the stock code this is handled by ScheduleCheckStockCodeAvailabilityProcessor.
I then run a function _bus.Defer(_checkStockCodeAvailability.TimeOutTime, message.StockCode);
My actual 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;
});
}
}
The code above works fine.
public class ScheduleCheckStockCodeAvailabilityProcessor : IHandleMessages<ScheduleCheckStockAvailabilityCommand>
{
readonly ICheckStockCodeAvailability _checkStockCodeAvailability;
readonly IBus _bus;
public ScheduleCheckStockCodeAvailabilityProcessor(ICheckStockCodeAvailability checkStockCodeAvailability, IBus bus)
{
_checkStockCodeAvailability = checkStockCodeAvailability;
_bus = bus;
}
public void Handle(ScheduleCheckStockAvailabilityCommand message)
{
_bus.Defer(_checkStockCodeAvailability.TimeOutTime, message.StockCode);
}
}
But I can't think of logically how this would work.
Any help?