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 Consume(InMemoryTransportMessage message, CancellationToken cancellationToken) { await Ready.ConfigureAwait(false); if (IsStopped) { return; } var context = new InMemoryReceiveContext(_inputAddress, message, _receiveEndpointContext); using (_tracker.BeginDelivery()) { try { await _receiveEndpointContext.ReceiveObservers.PreReceive(context).ConfigureAwait(false); await _receiveEndpointContext.ReceivePipe.Send(context).ConfigureAwait(false); await context.ReceiveCompleted.ConfigureAwait(false); await _receiveEndpointContext.ReceiveObservers.PostReceive(context).ConfigureAwait(false); } catch (Exception ex) { await _receiveEndpointContext.ReceiveObservers.ReceiveFault(context, ex).ConfigureAwait(false); message.DeliveryCount++; } 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(_inputAddress, message, _context); var delivery = _tracker.BeginDelivery(); var activity = LogContext.IfEnabled(OperationName.Transport.Receive)?.StartActivity(); activity.AddReceiveContextHeaders(context); try { if (_context.ReceiveObservers.Count > 0) { await _context.ReceiveObservers.PreReceive(context).ConfigureAwait(false); } await _context.ReceivePipe.Send(context).ConfigureAwait(false); await context.ReceiveCompleted.ConfigureAwait(false); if (_context.ReceiveObservers.Count > 0) { await _context.ReceiveObservers.PostReceive(context).ConfigureAwait(false); } } catch (Exception ex) { if (_context.ReceiveObservers.Count > 0) { await _context.ReceiveObservers.ReceiveFault(context, ex).ConfigureAwait(false); } message.DeliveryCount++; } finally { activity?.Stop(); delivery.Dispose(); 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 Consume(InMemoryTransportMessage message, CancellationToken cancellationToken) { await Ready.ConfigureAwait(false); if (IsStopped) { return; } if (_receivePipe == null) { throw new ArgumentException("ReceivePipe not configured"); } var context = new InMemoryReceiveContext(_inputAddress, message, _receiveObservable, _topology); context.GetOrAddPayload(() => _errorTransport); context.GetOrAddPayload(() => _deadLetterTransport); using (_tracker.BeginDelivery()) { try { await _receiveObservable.PreReceive(context).ConfigureAwait(false); await _receivePipe.Send(context).ConfigureAwait(false); await context.CompleteTask.ConfigureAwait(false); await _receiveObservable.PostReceive(context).ConfigureAwait(false); } catch (Exception ex) { await _receiveObservable.ReceiveFault(context, ex).ConfigureAwait(false); message.DeliveryCount++; } finally { context.Dispose(); } } }