public async Task Initialise(CancellationToken cancellationToken) { await handlerInvoker .Initialise(cancellationToken) .ConfigureAwait(false); pipelineStartingAction = BuildPipeline(); }
public Task Process(IncomingMessage message, Context context, IncomingPipelineAction nextAction) { if (!logger.IsEnabled(logLevel)) { return(nextAction(message, context)); } return(ProcessCore(message, context, nextAction)); }
public async Task Process(IncomingMessage message, Context context, IncomingPipelineAction next) { try { await next(message, context) .ConfigureAwait(false); } finally { finishedWithinSafeLockTime.Enqueue( FinishedWithinSafeTime(message)); TrimMetrics(); } }
public Task Process(IncomingMessage message, Context context, IncomingPipelineAction next) { var domainUnderTest = message.Headers.GetValueOrDefault(Constants.HeaderName); if (domainUnderTest != null && !string.Equals(endpointName, domainUnderTest, StringComparison.OrdinalIgnoreCase) && !endpointName.StartsWith(domainUnderTest + ".", StringComparison.OrdinalIgnoreCase)) { logger.LogInformation( $"Message {message.Id} of type \"{message.MessageTypeNames.First()}\" was ignored because it was part of a test of the \"{domainUnderTest}\" domain and the current endpoint name is \"{endpointName}\" which is outside that domain."); return(Task.CompletedTask); } incomingDomainUnderTestHeaderValue.Value = domainUnderTest; return(next(message, context)); }
public async Task Process(IncomingMessage message, Context context, IncomingPipelineAction next) { var correlationId = message.Headers.GetValueOrDefault(SharedConstants.CorrelationIdHeaderName); if (string.IsNullOrWhiteSpace(correlationId)) { correlationId = Guid.NewGuid().ToString(); } incomingCorrelationIdHeaderValue.Value = correlationId; using (logger.BeginScope("Handling message with correlation id {CorrelationId}", correlationId)) { await next(message, context) .ConfigureAwait(false); } }
private IncomingPipelineAction BuildPipeline() { IncomingPipelineAction lastAction = handlerInvoker.Process; var nextAction = lastAction; foreach (var behaviour in behaviours.Reverse()) { var capturedNextAction = nextAction; nextAction = (message, context) => behaviour.Process(message, context, capturedNextAction); } foreach (var behaviour in behaviours) { logger.LogDebug($"Adding {behaviour.GetType().Name} to incoming pipeline."); } return(nextAction); }
private async Task ProcessCore(IncomingMessage message, Context context, IncomingPipelineAction nextAction) { var correlationId = message.Headers.GetValueOrDefault(SharedConstants.CorrelationIdHeaderName); var typeName = message.MessageTypeNames.First(); logger.Log( logLevel, $"HANDLING {typeName} (id={message.Id}; correlationId={correlationId}; attempt={message.DequeuedCount}; remainingLockTime={message.RemainingLockTime})"); try { await nextAction(message, context) .ConfigureAwait(false); } catch (Exception exception) { logger.LogError( exception, $"Error when handling {typeName} (id={message.Id}): {exception.Message}"); throw; } }
public async Task Process(IncomingMessage message, Context context, IncomingPipelineAction nextAction) { var remainingLockTime = message.RemainingLockTime; if (remainingLockTime <= TimeSpan.Zero || !await semaphore .WaitAsync(remainingLockTime, context.CancellationToken) .ConfigureAwait(false)) { throw new MessageConcurrencyException( $"The concurrent-processing limit of {maximumMessagesProcessedInParallel} messages was reached and a slot did not become available before the remaining lock time for this message was exceeded."); } try { await nextAction(message, context) .ConfigureAwait(false); } finally { semaphore.Release(); } }