void HandleMessage(IMessage message) { Task.Run(async() => { LogContext.Current = _context.LogContext; if (IsStopping) { await WaitAndAbandonMessage().ConfigureAwait(false); return; } var context = new ActiveMqReceiveContext(message, _context, _receiveSettings, _session, _session.ConnectionContext); if (!_pending.TryAdd(message.NMSMessageId, context)) { LogContext.Warning?.Log("Duplicate message: {MessageId}", message.NMSMessageId); } try { await _dispatcher.Dispatch(context, context).ConfigureAwait(false); } catch (Exception exception) { context.LogTransportFaulted(exception); } finally { _pending.TryRemove(message.NMSMessageId, out _); context.Dispose(); } }); }
void HandleMessage(IMessage message) { _executor.PushWithWait(async() => { LogContext.Current = _context.LogContext; if (IsStopping) { await WaitAndAbandonMessage().ConfigureAwait(false); return; } var context = new ActiveMqReceiveContext(message, _context, _receiveSettings, _session, _session.ConnectionContext); try { await _dispatcher.Dispatch(context, context).ConfigureAwait(false); } catch (Exception exception) { context.LogTransportFaulted(exception); } finally { context.Dispose(); } }, Stopping); }
async Task HandleMessage(Message message) { if (IsStopping) { return; } var redelivered = message.Attributes.TryGetInt("ApproximateReceiveCount", out var receiveCount) && receiveCount > 1; var context = new AmazonSqsReceiveContext(message, redelivered, _context, _client, _receiveSettings, _client.ConnectionContext); try { await _dispatcher.Dispatch(context, context).ConfigureAwait(false); } catch (Exception exception) { context.LogTransportFaulted(exception); } finally { context.Dispose(); } }
public async Task Consume(InMemoryTransportMessage message, CancellationToken cancellationToken) { await Ready.ConfigureAwait(false); if (IsStopped) { return; } LogContext.Current = _context.LogContext; var context = new InMemoryReceiveContext(message, _context); try { await _dispatcher.Dispatch(context).ConfigureAwait(false); } catch (Exception exception) { message.DeliveryCount++; context.LogTransportFaulted(exception); } finally { context.Dispose(); } }
public async Task HandleMessage(Message message) { await Task.Run(async() => { if (IsStopping) { await WaitAndAbandonMessage().ConfigureAwait(false); return; } var redelivered = message.Attributes.TryGetValue("ApproximateReceiveCount", out var receiveCountStr) && int.TryParse(receiveCountStr, out var receiveCount) && receiveCount > 1; var context = new AmazonSqsReceiveContext(message, redelivered, _context, _client, _receiveSettings, _client.ConnectionContext); if (!_pending.TryAdd(message.MessageId, context)) { LogContext.Error?.Log("Duplicate message: {MessageId}", message.MessageId); } try { await _dispatcher.Dispatch(context, context).ConfigureAwait(false); } finally { _pending.TryRemove(message.MessageId, out _); context.Dispose(); } }); }
public void HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, IBasicProperties properties, ReadOnlyMemory <byte> body) { byte[] bodyBytes = body.ToArray(); Task.Run(async() => { LogContext.Current = _context.LogContext; var context = new RabbitMqReceiveContext(exchange, routingKey, _consumerTag, deliveryTag, bodyBytes, redelivered, properties, _context, _receiveSettings, _model, _model.ConnectionContext); if (!_pending.TryAdd(deliveryTag, context)) { LogContext.Warning?.Log("Duplicate BasicDeliver: {DeliveryTag}", deliveryTag); } var receiveLock = _receiveSettings.NoAck ? default : new RabbitMqReceiveLockContext(_model, deliveryTag); try { await _dispatcher.Dispatch(context, receiveLock).ConfigureAwait(false); } catch (Exception exception) { context.LogTransportFaulted(exception); } finally { _pending.TryRemove(deliveryTag, out _); context.Dispose(); } }); }
public async Task Handle(ProcessEventArgs eventArgs, CancellationToken cancellationToken) { if (!eventArgs.HasEvent) { return; } var context = new EventDataReceiveContext(eventArgs, _context, _lockContext); CancellationTokenRegistration registration; if (cancellationToken.CanBeCanceled) { registration = cancellationToken.Register(context.Cancel); } try { await _dispatcher.Dispatch(context, context).ConfigureAwait(false); } finally { registration.Dispose(); context.Dispose(); } }
async Task Handle(ProcessEventArgs eventArgs) { var context = new EventHubReceiveContext(eventArgs, _context, _processorContext); try { await _dispatcher.Dispatch(context, context).ConfigureAwait(false); } finally { context.Dispose(); } }
async Task IEventDataReceiver.Handle(EventData message, Action <ReceiveContext> contextCallback) { var context = new EventDataReceiveContext(message, _context); contextCallback?.Invoke(context); try { await _dispatcher.Dispatch(context).ConfigureAwait(false); } finally { context.Dispose(); } }
public void HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, IBasicProperties properties, ReadOnlyMemory <byte> body) { var bodyBytes = body.ToArray(); Task.Run(async() => { LogContext.Current = _context.LogContext; var context = new RabbitMqReceiveContext(exchange, routingKey, _consumerTag, deliveryTag, bodyBytes, redelivered, properties, _context, _receiveSettings, _model, _model.ConnectionContext); var added = _pending.TryAdd(deliveryTag, context); if (!added && deliveryTag != 1) // DIRECT REPLY-TO fixed value { LogContext.Warning?.Log("Duplicate BasicDeliver: {DeliveryTag}", deliveryTag); } var receiveLock = _receiveSettings.NoAck ? default : new RabbitMqReceiveLockContext(_model, deliveryTag); if (_limit != null) { await _limit.WaitAsync(context.CancellationToken).ConfigureAwait(false); } try { await _dispatcher.Dispatch(context, receiveLock).ConfigureAwait(false); } catch (Exception exception) { context.LogTransportFaulted(exception); } finally { _limit?.Release(); if (added) { _pending.TryRemove(deliveryTag, out _); } context.Dispose(); } }); }
async Task StartDispatcher() { LogContext.Current = _context.LogContext; try { await Ready.ConfigureAwait(false); while (await _channel.Reader.WaitToReadAsync(Stopping).ConfigureAwait(false)) { var message = await _channel.Reader.ReadAsync(Stopping).ConfigureAwait(false); if (_limiter != null) { await _limiter.Wait(Stopping).ConfigureAwait(false); } _ = Task.Run(async() => { var context = new GrpcReceiveContext(message, _context); try { await _dispatcher.Dispatch(context).ConfigureAwait(false); } catch (Exception exception) { context.LogTransportFaulted(exception); } finally { _limiter?.Release(); context.Dispose(); } }, Stopping); } } catch (OperationCanceledException) { } catch (Exception exception) { LogContext.Warning?.Log(exception, "Consumer dispatcher faulted: {Queue}", _queueName); } }
public async Task Handle(ConsumeResult <TKey, TValue> result, CancellationToken cancellationToken) { var context = new ConsumeResultReceiveContext <TKey, TValue>(result, _context, _lockContext, _headersDeserializer); CancellationTokenRegistration registration; if (cancellationToken.CanBeCanceled) { registration = cancellationToken.Register(context.Cancel); } try { await _dispatcher.Dispatch(context, context).ConfigureAwait(false); } finally { registration.Dispose(); context.Dispose(); } }
async Task Handle(ConsumeResult <TKey, TValue> result) { if (IsStopping) { return; } var context = new ConsumeResultReceiveContext <TKey, TValue>(result, _context, _consumerContext, _consumerContext.HeadersDeserializer); try { await _dispatcher.Dispatch(context, context).ConfigureAwait(false); } catch (Exception exception) { context.LogTransportFaulted(exception); } finally { context.Dispose(); } }
void IBasicConsumer.HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, IBasicProperties properties, byte[] body) { Task.Run(async() => { LogContext.Current = _context.LogContext; if (IsStopping && _receiveSettings.NoAck == false) { await WaitAndAbandonMessage(deliveryTag).ConfigureAwait(false); return; } var context = new RabbitMqReceiveContext(exchange, routingKey, _consumerTag, deliveryTag, body, redelivered, properties, _context, _receiveSettings, _model, _model.ConnectionContext); if (!_pending.TryAdd(deliveryTag, context)) { LogContext.Warning?.Log("Duplicate BasicDeliver: {DeliveryTag}", deliveryTag); } var receiveLock = _receiveSettings.NoAck ? default : new RabbitMqReceiveLockContext(_model, deliveryTag); try { await _dispatcher.Dispatch(context, receiveLock).ConfigureAwait(false); } catch (Exception exception) { context.LogTransportFaulted(exception); } finally { _pending.TryRemove(deliveryTag, out _); context.Dispose(); } }); }
async Task IEventDataReceiver.Handle(EventData message, CancellationToken cancellationToken, Action <ReceiveContext> contextCallback) { var context = new EventDataReceiveContext(message, _context); contextCallback?.Invoke(context); CancellationTokenRegistration registration; if (cancellationToken.CanBeCanceled) { registration = cancellationToken.Register(context.Cancel); } try { await _dispatcher.Dispatch(context).ConfigureAwait(false); } finally { registration.Dispose(); context.Dispose(); } }