public async Task HandleErrorAsync <TCommand>(ICommandContext <TCommand> context, Exception exception, CommandErrorDelegate <TCommand> next) where TCommand : class, ICommand { if (context.Message is CommandMessage <TCommand> message) { var retryCount = RetryCount(message) + 1; if (retryCount < _options.MaxRetries) { _logger.LogTrace($"Error {retryCount}/{_options.MaxRetries}: will retry"); message.Headers[Headers.RetryCount] = retryCount.Stringfy(); await _engine.NotifySuccessAsync(message).ConfigureAwait(false); await _engine.SendMessageAsync(message).ConfigureAwait(false); } else { _logger.LogTrace($"Error {retryCount}/{_options.MaxRetries}: will not retry"); //await _engine.NotifyFailAsync(message).ConfigureAwait(false); await next(context, exception).ConfigureAwait(false); } } }
public Task InvokeCommandAsync <TCommand>(TCommand command, Guid correlationId, IDictionary <string, string> headers) where TCommand : class, ICommand { var message = new CommandMessage <TCommand> { MessageId = Guid.NewGuid().Stringfy(), Headers = new HeaderBag(headers) { CorrelationId = correlationId, SentOn = Clock.Default.Now }, Command = command }; _logger.LogTrace(new { type = typeof(TCommand).FullName, correlationId = correlationId, message }, arg => $"Invoking command of type {arg.type} with correlationId {arg.correlationId}. Command: {arg.message.Command.ToString()}"); return(_engine.SendMessageAsync(message)); }