public async Task ProcessAsync(IEventContext <T> context) { try { await context.InvokeNextAsync(); } catch (Exception ex) { _logger.LogWarning($"Failed to handle the message. Retry in {_retryTimeout.TotalSeconds} sec. Exception {ex}"); // Retries loop for (int i = 0; i < _retryNum; i++) { // Adding delay between attempts await Task.Delay(_retryTimeout, context.CancellationToken); try { await context.InvokeNextAsync(); return; } catch (Exception ex2) { _logger.LogWarning( $"Retry attempt: failed to handle the message for the {i + 1} time. Retry in {_retryTimeout.TotalSeconds} sec. Exception {ex2}"); } } throw; } }
public Task ProcessAsync(IEventContext <T> context) { var deduplicationHeaderBytes = string.IsNullOrEmpty(_deduplicatorHeader) || !context.BasicDeliverEventArgs.BasicProperties.Headers.ContainsKey(_deduplicatorHeader) ? Array.Empty <byte>() : Encoding.UTF8.GetBytes( JsonConvert.SerializeObject( context.BasicDeliverEventArgs.BasicProperties.Headers[_deduplicatorHeader], new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore })); var deduplicationBytes = deduplicationHeaderBytes.Length == 0 ? context.BasicDeliverEventArgs.Body : deduplicationHeaderBytes; var hash = HashHelper.GetMd5Hash(deduplicationBytes); lock (Cache) { if (Cache.TryGetValue(hash, out object _)) { context.MessageAcceptor.Accept(); return(Task.CompletedTask); } Cache.Set(hash, true, _expiration); return(context.InvokeNextAsync()); } }
public async Task ProcessAsync(IEventContext <T> context) { try { await context.InvokeNextAsync(); } catch (Exception ex) { _logger.LogError(ex, context.Settings.GetSubscriberName()); context.MessageAcceptor.Accept(); } }
public async Task ProcessAsync(IEventContext <T> context) { try { await context.InvokeNextAsync(); } catch (Exception ex) { _logger.LogError( ex, $"Failed to handle the message. Sending it to poison queue {context.Settings.GetSubscriberName()} {context.Settings.QueueName}-poison."); context.MessageAcceptor.Reject(); } }
public Task ProcessAsync(IEventContext <T> context) { if (_queueName == null) { _queueName = context.Settings.GetQueueOrExchangeName(); } var telemetryOperation = InitTelemetryOperation(_queueName, context.BasicDeliverEventArgs.Body.Length); try { return(context.InvokeNextAsync()); } catch (Exception e) { telemetryOperation.Telemetry.Success = false; _telemetry.TrackException(e); throw; } finally { _telemetry.StopOperation(telemetryOperation); } }