public void LogInboundLowLevelTrace_NoException_Logged() { var envelope = new RawInboundEnvelope( Stream.Null, new MessageHeaderCollection { { DefaultMessageHeaders.MessageType, "Message.Type" }, { DefaultMessageHeaders.MessageId, "1234" } }, new TestConsumerEndpoint("test1, test2"), "test1", new TestOffset("a", "42")); var expectedMessage = "BatchSequence 'batch123' processing has completed... | " + "endpointName: test1, " + "messageType: Message.Type, " + "messageId: 1234, " + "unused1: (null), " + "unused2: (null)"; _inboundLogger.LogInboundLowLevelTrace( "{sequenceType} '{sequenceId}' processing has completed...", envelope, () => new object[] { "BatchSequence", "batch123" }); _loggerSubstitute.Received(LogLevel.Trace, null, expectedMessage, 1999); }
public void LogInboundLowLevelTrace_NoException_Logged() { var envelope = new RawInboundEnvelope( Stream.Null, new MessageHeaderCollection { { DefaultMessageHeaders.MessageType, "Message.Type" }, { DefaultMessageHeaders.MessageId, "1234" }, { KafkaMessageHeaders.KafkaMessageKey, "key1234" } }, new KafkaConsumerEndpoint("topic1", "topic2"), "topic2", new KafkaOffset("topic2", 2, 42)); var expectedMessage = "BatchSequence 'batch123' processing has completed... | " + "endpointName: topic2, " + "messageType: Message.Type, " + "messageId: 1234, " + "offset: [2]@42, " + "kafkaKey: key1234"; _inboundLogger.LogInboundLowLevelTrace( "{sequenceType} '{sequenceId}' processing has completed...", envelope, () => new object[] { "BatchSequence", "batch123" }); _loggerSubstitute.Received(LogLevel.Trace, null, expectedMessage, 1999); }
private async Task PublishSequenceAsync(ISequence sequence, ConsumerPipelineContext context) { var processingTask = await PublishStreamProviderAsync(sequence, context).ConfigureAwait(false); context.ProcessingTask = processingTask; _logger.LogInboundLowLevelTrace( "Published {sequenceType} '{sequenceId}' (ProcessingTask.Id={processingTaskId}).", context.Envelope, () => new object[] { sequence.GetType().Name, sequence.SequenceId, processingTask.Id }); }
public async Task HandleAsync(ConsumerPipelineContext context, ConsumerBehaviorHandler next) { Check.NotNull(context, nameof(context)); Check.NotNull(next, nameof(next)); try { var scope = context.ServiceProvider.CreateScope(); context.ReplaceServiceScope(scope); context.TransactionManager = new ConsumerTransactionManager( context, context.ServiceProvider .GetRequiredService <IInboundLogger <ConsumerTransactionManager> >()); _logger.LogProcessing(context.Envelope); await next(context).ConfigureAwait(false); if (context.Sequence == null) { await context.TransactionManager.CommitAsync().ConfigureAwait(false); context.Dispose(); } else { if (context.IsSequenceStart) { StartSequenceProcessingAwaiter(context); } await AwaitProcessedIfNecessaryAsync(context).ConfigureAwait(false); } } catch (Exception exception) { // Sequence errors are handled in AwaitSequenceProcessingAsync, just await the rollback and // rethrow (-> if the exception bubbled up till this point, it's because it failed to be // handled and it's safer to stop the consumer) if (context.Sequence != null) { await context.Sequence.AbortAsync(SequenceAbortReason.Error, exception) .ConfigureAwait(false); if (context.Sequence.Length > 0) { _logger.LogInboundLowLevelTrace( "Awaiting sequence processing completed before rethrowing.", context.Envelope); await context.Sequence.AwaitProcessingAsync(false).ConfigureAwait(false); } throw; } if (!await HandleExceptionAsync(context, exception).ConfigureAwait(false)) { throw; } } }