public static IRawInboundEnvelope CreateTypedInboundEnvelope( IRawInboundEnvelope rawInboundEnvelope, object?deserializedMessage, Type messageType) { var typedInboundMessage = (InboundEnvelope)Activator.CreateInstance( typeof(InboundEnvelope <>).MakeGenericType(messageType), rawInboundEnvelope, deserializedMessage); return(typedInboundMessage); }
public void LogInboundLowLevelTrace( string message, IRawInboundEnvelope envelope, Exception?exception, Func <object?[]>?argumentsProvider = null) => _loggerFactory.GetInboundLogger(envelope.Endpoint).LogInboundTrace( this, IntegrationLogEvents.LowLevelTracing.Level, IntegrationLogEvents.LowLevelTracing.EventId, message, envelope, exception, argumentsProvider);
public Task <bool> ExistsAsync(IRawInboundEnvelope envelope) { Check.NotNull(envelope, nameof(envelope)); string messageId = envelope.Headers.GetValue(DefaultMessageHeaders.MessageId, true) !; string consumerGroupName = envelope.Endpoint.GetUniqueConsumerGroupName(); return(DbSet.AsQueryable().AnyAsync( logEntry => logEntry.MessageId == messageId && logEntry.EndpointName == envelope.ActualEndpointName && logEntry.ConsumerGroupName == consumerGroupName)); }
/// <inheritdoc cref="SequenceBase{TEnvelope}.AddCoreAsync" /> protected override Task <int> AddCoreAsync(IRawInboundEnvelope envelope, ISequence?sequence, bool throwIfUnhandled) { Check.NotNull(envelope, nameof(envelope)); var chunkIndex = envelope.Headers.GetValue <int>(DefaultMessageHeaders.ChunkIndex) ?? throw new InvalidOperationException("Chunk index header not found."); if (!EnsureOrdering(chunkIndex)) { return(Task.FromResult(0)); } return(base.AddCoreAsync(envelope, sequence, throwIfUnhandled)); }
/// <inheritdoc cref="IInboundLog.ExistsAsync" /> public Task <bool> ExistsAsync(IRawInboundEnvelope envelope) { Check.NotNull(envelope, nameof(envelope)); string messageId = envelope.Headers.GetValue(DefaultMessageHeaders.MessageId, true) !; string consumerGroupName = envelope.Endpoint.GetUniqueConsumerGroupName(); return(Task.FromResult( Items.Union(UncommittedItems).Any( item => item.Item.MessageId == messageId && item.Item.EndpointName == envelope.ActualEndpointName && item.Item.ConsumerGroupName == consumerGroupName))); }
private async Task PublishToNewEndpointAsync(IRawInboundEnvelope envelope, Exception exception) { envelope.Headers.AddOrReplace( DefaultMessageHeaders.SourceEndpoint, envelope.Endpoint?.Name ?? string.Empty); var outboundEnvelope = envelope is IInboundEnvelope deserializedEnvelope ? new OutboundEnvelope(deserializedEnvelope.Message, deserializedEnvelope.Headers, _endpoint) : new OutboundEnvelope(envelope.RawMessage, envelope.Headers, _endpoint); _transformationAction?.Invoke(outboundEnvelope, exception); await _producer.ProduceAsync(outboundEnvelope).ConfigureAwait(false); }
/// <inheritdoc cref="IInboundLog.AddAsync" /> public Task AddAsync(IRawInboundEnvelope envelope) { Check.NotNull(envelope, nameof(envelope)); string messageId = envelope.Headers.GetValue(DefaultMessageHeaders.MessageId, true) !; string consumerGroupName = envelope.Endpoint.GetUniqueConsumerGroupName(); var logEntry = new InboundLogEntry { MessageId = messageId, EndpointName = envelope.ActualEndpointName, ConsumerGroupName = consumerGroupName }; return(AddAsync(logEntry)); }
private async Task PublishToNewEndpointAsync(IRawInboundEnvelope envelope, Exception exception) { var outboundEnvelope = envelope is IInboundEnvelope deserializedEnvelope ? new OutboundEnvelope( deserializedEnvelope.Message, deserializedEnvelope.Headers, _endpoint) : new OutboundEnvelope(envelope.RawMessage, envelope.Headers, _endpoint); var enricher = _enricherFactory.GetMovePolicyEnricher(envelope.Endpoint); enricher.Enrich(envelope, outboundEnvelope, exception); _transformationAction?.Invoke(outboundEnvelope, exception); await _producer.ProduceAsync(outboundEnvelope).ConfigureAwait(false); }
public static void LogMessageAddedToSequence( this ISilverbackLogger logger, IRawInboundEnvelope envelope, ISequence sequence) { if (!logger.IsEnabled(IntegrationLogEvents.MessageAddedToSequence)) { return; } MessageAddedToSequence( logger.InnerLogger, envelope.Headers.GetValue(DefaultMessageHeaders.MessageId), sequence.GetType().Name, sequence.SequenceId, sequence.Length, null); }
public void LogSequenceAborted( IRawInboundEnvelope envelope, ISequence sequence, SequenceAbortReason reason, Exception?exception) { switch (reason) { case SequenceAbortReason.Error: LogWithMessageInfo( LogLevel.Warning, IntegrationEventIds.ErrorProcessingInboundMessage, exception, "Error occurred processing the inbound sequence of messages.", envelope, sequence); break; case SequenceAbortReason.IncompleteSequence: LogWithMessageInfo( LogLevel.Warning, IntegrationEventIds.IncompleteSequenceDiscarded, null, "The incomplete sequence is discarded.", envelope, sequence); break; case SequenceAbortReason.EnumerationAborted: case SequenceAbortReason.ConsumerAborted: case SequenceAbortReason.Disposing: LogWithMessageInfo( LogLevel.Debug, IntegrationEventIds.SequenceProcessingAborted, null, $"The sequence processing has been aborted (reason: {reason}).", envelope, sequence); break; default: throw new ArgumentOutOfRangeException(nameof(reason), reason, null); } }
private object?[] GetInboundLogArguments(IRawInboundEnvelope envelope, ref string logMessage) { logMessage += LogTemplates.GetInboundMessageLogTemplate(envelope.Endpoint); var arguments = new List <object?> { envelope.ActualEndpointName, envelope.Headers.GetValueOrDefault <int>(DefaultMessageHeaders.FailedAttempts), envelope.Headers.GetValue(DefaultMessageHeaders.MessageType), envelope.Headers.GetValue(DefaultMessageHeaders.MessageId) }; foreach (string key in LogTemplates.GetInboundMessageArguments(envelope.Endpoint)) { arguments.Add(envelope.AdditionalLogData.TryGetValue(key, out string value) ? value : null); } return(arguments.ToArray()); }
public void LogInboundTrace( LogEvent logEvent, IRawInboundEnvelope envelope, Exception?exception, Func <object?[]>?argumentsProvider = null) { if (logEvent.Level > LogLevel.Trace) { throw new InvalidOperationException("This method is intended for tracing only."); } _loggerFactory.GetInboundLogger(envelope.Endpoint).LogInboundTrace( this, logEvent.Level, logEvent.EventId, logEvent.Message, envelope, exception, argumentsProvider); }
public void LogProcessing(ISilverbackLogger logger, IRawInboundEnvelope envelope) { if (!logger.IsEnabled(IntegrationLogEvents.ProcessingInboundMessage)) { return; } (string?value1, string?value2) = _logEnricher.GetAdditionalValues( envelope.Endpoint, envelope.Headers, envelope.BrokerMessageIdentifier); _processingInboundMessage.Invoke( logger.InnerLogger, envelope.ActualEndpointDisplayName, envelope.Headers.GetValue(DefaultMessageHeaders.MessageType), envelope.Headers.GetValue(DefaultMessageHeaders.MessageId), value1, value2, null); }
private static IRawInboundEnvelope?HandleNullMessage( ConsumerPipelineContext context, IRawInboundEnvelope envelope, Type deserializedType) { switch (context.Consumer.Endpoint.NullMessageHandlingStrategy) { case NullMessageHandlingStrategy.Tombstone: return(CreateTombstoneEnvelope(envelope, deserializedType)); case NullMessageHandlingStrategy.Legacy: return(SerializationHelper.CreateTypedInboundEnvelope( envelope, null, deserializedType)); case NullMessageHandlingStrategy.Skip: return(null); default: throw new InvalidOperationException("Unknown NullMessageHandling value."); } }
private static Tombstone CreateTombstone(Type?deserializedType, IRawInboundEnvelope envelope) { var messageId = envelope.Headers.GetValue(DefaultMessageHeaders.MessageId); if (deserializedType == null) { envelope.Headers.AddOrReplace( DefaultMessageHeaders.MessageType, typeof(Tombstone).AssemblyQualifiedName); return(new Tombstone(messageId)); } var tombstoneType = typeof(Tombstone <>).MakeGenericType(deserializedType); envelope.Headers.AddOrReplace( DefaultMessageHeaders.MessageType, tombstoneType.AssemblyQualifiedName); return((Tombstone)Activator.CreateInstance( tombstoneType, messageId)); }
public void LogRollbackToSkipFailed( ISilverbackLogger logger, IRawInboundEnvelope envelope, Exception exception) { if (!logger.IsEnabled(IntegrationLogEvents.RollbackToSkipFailed)) { return; } (string?value1, string?value2) = _logEnricher.GetAdditionalValues( envelope.Endpoint, envelope.Headers, envelope.BrokerMessageIdentifier); _rollbackToSkipFailed.Invoke( logger.InnerLogger, envelope.ActualEndpointDisplayName, envelope.Headers.GetValue(DefaultMessageHeaders.MessageType), envelope.Headers.GetValue(DefaultMessageHeaders.MessageId), value1, value2, exception); }
public IntegrationLoggingBenchmark() { var serviceProvider = ServiceProviderHelper.GetServiceProvider( services => services .AddFakeLogger() .AddSilverback() .WithConnectionToMessageBroker(broker => broker.AddKafka())); _inboundLogger = serviceProvider.GetRequiredService <IInboundLogger <IntegrationLoggingBenchmark> >(); _outboundLogger = serviceProvider.GetRequiredService <IOutboundLogger <IntegrationLoggingBenchmark> >(); _inboundEnvelope = new RawInboundEnvelope( Array.Empty <byte>(), new MessageHeaderCollection { new("Test", "Test"), new(DefaultMessageHeaders.FailedAttempts, "1"), new(DefaultMessageHeaders.MessageType, "Something.Xy"), new(DefaultMessageHeaders.MessageId, "1234"), new(KafkaMessageHeaders.KafkaMessageKey, "key1234") },
public void LogProcessingFatalError( ISilverbackLogger logger, IRawInboundEnvelope envelope, Exception exception) { if (!logger.IsEnabled(IntegrationLogEvents.ConsumerFatalError)) { return; } (string?value1, string?value2) = _logEnricher.GetAdditionalValues( envelope.Endpoint, envelope.Headers, envelope.BrokerMessageIdentifier); _consumerFatalError.Invoke( logger.InnerLogger, envelope.ActualEndpointName, envelope.Headers.GetValue(DefaultMessageHeaders.MessageType), envelope.Headers.GetValue(DefaultMessageHeaders.MessageId), value1, value2, exception); }
public void LogInboundLowLevelTrace( string message, IRawInboundEnvelope envelope, Func <object?[]>?argumentsProvider = null) => LogInboundLowLevelTrace(message, envelope, null, argumentsProvider);
public void LogInboundTrace( LogEvent logEvent, IRawInboundEnvelope envelope, Func <object?[]>?argumentsProvider = null) => LogInboundTrace(logEvent, envelope, null, argumentsProvider);
public void LogRollbackToSkipFailed(IRawInboundEnvelope envelope, Exception exception) => _loggerFactory.GetInboundLogger(envelope.Endpoint) .LogRollbackToSkipFailed(this, envelope, exception);
public void LogCannotMoveSequences(IRawInboundEnvelope envelope, ISequence sequence) => _loggerFactory.GetInboundLogger(envelope.Endpoint) .LogCannotMoveSequences(this, envelope, sequence);
public void LogMoved(IRawInboundEnvelope envelope, IProducerEndpoint targetEndpoint) => _loggerFactory.GetInboundLogger(envelope.Endpoint) .LogMoved(this, envelope, targetEndpoint);
public void LogProcessingFatalError(IRawInboundEnvelope envelope, Exception exception) => _loggerFactory.GetInboundLogger(envelope.Endpoint) .LogProcessingFatalError(this, envelope, exception);
public static RawInboundEnvelope CloneReplacingStream(this IRawInboundEnvelope envelope, Stream?rawMessage) =>
public void LogNullMessageSkipped(IRawInboundEnvelope envelope) => _loggerFactory.GetInboundLogger(envelope.Endpoint) .LogNullMessageSkipped(this, envelope);
public void Enrich(IRawInboundEnvelope inboundEnvelope, IOutboundEnvelope outboundEnvelope, Exception exception) { // Do nothing }
public void LogAlreadyProcessed(IRawInboundEnvelope envelope) => _loggerFactory.GetInboundLogger(envelope.Endpoint) .LogAlreadyProcessed(this, envelope);
public void LogRetryProcessing(IRawInboundEnvelope envelope) => _loggerFactory.GetInboundLogger(envelope.Endpoint) .LogRetryProcessing(this, envelope);
/// <inheritdoc cref="SequenceBase{TEnvelope}.IsLastMessage" /> protected override bool IsLastMessage(IRawInboundEnvelope envelope) { Check.NotNull(envelope, nameof(envelope)); return(envelope.Headers.GetValue <bool>(DefaultMessageHeaders.IsLastChunk) == true); }