public override async Task OnBatchAsync(IEnumerable <T> batch, IFeedbackSender feedbackSender, CancellationToken cancellationToken) { var invocationSuccess = false; var exceptions = new List <Exception>(); var tryCount = 0; while (tryCount == 0 || (!invocationSuccess && ShouldRetry(tryCount, exceptions))) { if (tryCount > 0 && InvokeRetryWaitMilliseconds > 0) { await Task.Delay(InvokeRetryWaitMilliseconds, cancellationToken).ConfigureAwait(false); } tryCount++; invocationSuccess = await TryInvokeBatchAsync(batch, exceptions, cancellationToken).ConfigureAwait(false); } if (invocationSuccess) { feedbackSender.Ack(); } else if (ShouldRequeue(exceptions)) { feedbackSender.Nack(true); } else { feedbackSender.Nack(false); } }
public override Task OnMessageAsync(T message, RabbitMQConsumerContext consumerContext, IFeedbackSender feedbackSender, CancellationToken cancellationToken) { try { _callbackAction(message, consumerContext); feedbackSender.Ack(); } catch (Exception e) { feedbackSender.Nack(true); } return(Task.FromResult(0)); }
public override async Task OnMessageAsync(T message, RabbitMQConsumerContext consumerContext, IFeedbackSender feedbackSender, CancellationToken cancellationToken) { try { using (var tokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken)) { tokenSource.CancelAfter(_processingTimeout); await _callbackFunc(message, consumerContext, tokenSource.Token).ConfigureAwait(false); } feedbackSender.Ack(); } catch (Exception e) { feedbackSender.Nack(true); } }
public override Task OnBatchAsync(IEnumerable <T> batch, IFeedbackSender feedbackSender, CancellationToken cancellationToken) { if (_batchCallbackAction == null) { throw new Exception("Undefined batch callback action"); } try { _batchCallbackAction(batch); feedbackSender.Ack(); } catch (Exception e) { feedbackSender.Nack(true); } return(Task.FromResult(0)); }
public override async Task OnBatchAsync(IEnumerable <T> batch, IFeedbackSender feedbackSender, CancellationToken cancellationToken) { if (_batchCallbackFunc == null) { throw new Exception("Undefined batch callback function"); } try { using (var tokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken)) { tokenSource.CancelAfter(_processingTimeout); await _batchCallbackFunc(batch, tokenSource.Token).ConfigureAwait(false); } feedbackSender.Ack(); } catch (Exception e) { feedbackSender.Nack(true); } }
public override async Task OnMessageAsync(T message, RabbitMQConsumerContext consumerContext, IFeedbackSender feedbackSender, CancellationToken cancellationToken) { var invocationSuccess = false; var exceptions = new List <Exception>(); var tryCount = 0; while (tryCount == 0 || (!invocationSuccess && ShouldRetry(tryCount, exceptions))) { if (tryCount > 0 && InvokeRetryWaitMilliseconds > 0) { await Task.Delay(InvokeRetryWaitMilliseconds, cancellationToken).ConfigureAwait(false); } tryCount++; invocationSuccess = await TryInvokeAsync(message, consumerContext, exceptions, cancellationToken).ConfigureAwait(false); } if (invocationSuccess) { feedbackSender.Ack(); } else if (ShouldRequeue(exceptions)) { feedbackSender.Nack(true); Logger.LogWarning(new AggregateException(exceptions), $"Message successfully processed, but exceptions were thrown after {tryCount} tries"); } else { feedbackSender.Nack(false); Logger.LogError(new AggregateException(exceptions), $"Unable to successfully process message after {tryCount} tries"); } }