public override async Task ProcessAsync(IConsumerPipeContext <T> context, ReadOnlyMemory <IConsumerPipe <T> > pipeline) { var rMessage = context.RabbitMqMessage; AddFinalAttemptHeader(context); try { await ProcessNextAsync(context, pipeline); if (context.ActiveMessageProcessorCanceller.IsInterrupted()) { return; } context.Chanel.BasicAck(rMessage.DeliveryTag, false); } catch (Exception) { if (rMessage.BasicProperties.Headers?.ContainsKey(_retryCountHeaderName) != true) { rMessage.BasicProperties.Headers ??= new Dictionary <string, object>(); rMessage.BasicProperties.Headers[_retryCountHeaderName] = 1; using (var channelContainer = await context.ConnectionManager.AcquireChannel(ChannelType.Publish)) channelContainer.Channel.BasicPublish(RabbitMqConstants.DefaultExchangeName, rMessage.RoutingKey, true, rMessage.BasicProperties, rMessage.Body); context.Chanel.BasicAck(rMessage.DeliveryTag, false); } else if (rMessage.BasicProperties.Headers?[_retryCountHeaderName] is int retryCount && retryCount < _maximumRetryCount) { rMessage.BasicProperties.Headers[_retryCountHeaderName] = retryCount + 1; using (var channelContainer = await context.ConnectionManager.AcquireChannel(ChannelType.Publish)) channelContainer.Channel.BasicPublish(RabbitMqConstants.DefaultExchangeName, rMessage.RoutingKey, true, rMessage.BasicProperties, rMessage.Body); context.Chanel.BasicAck(rMessage.DeliveryTag, false); }
public override async Task ProcessAsync(IConsumerPipeContext <T> context, ReadOnlyMemory <IConsumerPipe <T> > pipeline) { var rMessage = context.RabbitMqMessage; AddFinalAttemptHeader(context); try { await ProcessNextAsync(context, pipeline); context.Chanel.BasicAck(rMessage.DeliveryTag, false); } catch (Exception) { if (rMessage.BasicProperties.Headers?.ContainsKey(_retryCountHeaderName) != true) { rMessage.BasicProperties.Headers ??= new Dictionary <string, object>(); rMessage.BasicProperties.Headers[_retryCountHeaderName] = 1; rMessage.BasicProperties.Expiration = _retryDelays[0].TotalMilliseconds.ToString(CultureInfo.InvariantCulture); using (var channelContainer = await context.ConnectionManager.AcquireChannel(ChannelType.Publish)) channelContainer.Channel.BasicPublish(RabbitMqConstants.DefaultExchangeName, _delayedMessagesQueueName ?? DelayedQueueName(rMessage.RoutingKey), true, rMessage.BasicProperties, rMessage.Body); context.Chanel.BasicAck(rMessage.DeliveryTag, false); } else if (rMessage.BasicProperties.Headers?[_retryCountHeaderName] is int retryCount && retryCount < _retryDelays.Length) { rMessage.BasicProperties.Headers[_retryCountHeaderName] = retryCount + 1; rMessage.BasicProperties.Expiration = _retryDelays[retryCount].TotalMilliseconds.ToString(CultureInfo.InvariantCulture); using (var channelContainer = await context.ConnectionManager.AcquireChannel(ChannelType.Publish)) channelContainer.Channel.BasicPublish(RabbitMqConstants.DefaultExchangeName, _delayedMessagesQueueName ?? DelayedQueueName(rMessage.RoutingKey), true, rMessage.BasicProperties, rMessage.Body); context.Chanel.BasicAck(rMessage.DeliveryTag, false); }
protected Task ProcessNextAsync(IConsumerPipeContext <T> context, ReadOnlyMemory <IConsumerPipe <T> > pipeline) { if (context.ActiveMessageProcessorCanceller.IsInterrupted()) { return(Task.CompletedTask); } return(ExecutePipelineAsync(context, pipeline)); }
public override async Task ProcessAsync(IConsumerPipeContext <T> context, ReadOnlyMemory <IConsumerPipe <T> > pipeline) { try { await ProcessNextAsync(context, pipeline); } catch (Exception ex) { _logFunc(ex, context.TryGetOptionalItemValue(FinalAttemptItemsKey, out bool finalAttempt) && finalAttempt); throw; } }
public override async Task ProcessAsync(IConsumerPipeContext <T> context, ReadOnlyMemory <IConsumerPipe <T> > pipeline) { try { await ProcessNextAsync(context, pipeline); context.Items[FinalAttemptItemsKey] = true; context.Chanel.BasicAck(context.RabbitMqMessage.DeliveryTag, false); } catch (Exception) { context.Chanel.BasicReject(context.RabbitMqMessage.DeliveryTag, false); } }
public override Task ProcessAsync(IConsumerPipeContext <T> context, ReadOnlyMemory <IConsumerPipe <T> > pipeline) { var message = context.RabbitMqMessage; if (message.BasicProperties.ContentType != null && _options.Deserializers.ContainsKey(message.BasicProperties.ContentType)) { context.DeserializedMessage = _options.Deserializers[message.BasicProperties.ContentType](message.Body); } else if (_options.DefaultDeserializer != null) { context.DeserializedMessage = _options.DefaultDeserializer(message.Body); } else { throw new NotSupportedException($"No deserializer for {message.BasicProperties.ContentType} nor default serializer was provided"); } return(ProcessNextAsync(context, pipeline)); }
public override async Task ProcessAsync(IConsumerPipeContext <T> context, ReadOnlyMemory <IConsumerPipe <T> > pipeline) { try { var alreadyWorking = context.ActiveMessageProcessorCanceller.BeginProcessing(); if (context.ActiveMessageProcessorCanceller.StopProcessingNewMessageToken.IsCancellationRequested) { return; } if (!alreadyWorking) { throw new ProcessingAlreadyInProgressException("A message processor is already in progress"); } await ProcessNextAsync(context, pipeline); } finally { context.ActiveMessageProcessorCanceller.EndProcessing(); } }
public Task ProcessAsync(IConsumerPipeContext <T> context, ReadOnlyMemory <IConsumerPipe <T> > pipeline) { return(context.MessageProcessor.Invoke(context.DeserializedMessage !, context.Items, context.ActiveMessageProcessorCanceller.InterruptInProgressProcessorToken)); }
public override async Task ProcessAsync(IConsumerPipeContext <T> context, ReadOnlyMemory <IConsumerPipe <T> > pipeline) { Task Next() => ProcessNextAsync(context, pipeline); await _pipeImpl.Invoke(context, Next); }
public abstract Task ProcessAsync(IConsumerPipeContext <T> context, ReadOnlyMemory <IConsumerPipe <T> > pipeline);
public static Task ExecutePipelineAsync(IConsumerPipeContext <T> context, ReadOnlyMemory <IConsumerPipe <T> > pipeline) { return(pipeline.Span[0].ProcessAsync(context, pipeline.Slice(1))); }
public static bool TryGetOptionalItemValue <TValue, T>(this IConsumerPipeContext <T> context, string key, out TValue value) where T : class { value = default !;