Пример #1
0
 public void LogWithMessageInfo(
     LogLevel logLevel,
     EventId eventId,
     Exception?exception,
     string logMessage,
     IRawOutboundEnvelope envelope) =>
 LogWithMessageInfo(logLevel, eventId, exception, logMessage, envelope, null, null);
Пример #2
0
        private void PublishToChannel(IRawOutboundEnvelope envelope)
        {
            _channel ??= _connectionFactory.GetChannel(Endpoint);

            var properties = _channel.CreateBasicProperties();

            properties.Persistent = true; // TODO: Make it configurable?
            properties.Headers    = envelope.Headers.ToDictionary(header => header.Name, header => (object?)header.Value);

            string?routingKey;

            switch (Endpoint)
            {
            case RabbitQueueProducerEndpoint queueEndpoint:
                routingKey = queueEndpoint.Name;
                _channel.BasicPublish(
                    string.Empty,
                    routingKey,
                    properties,
                    envelope.RawMessage.ReadAll());
                break;

            case RabbitExchangeProducerEndpoint exchangeEndpoint:
                routingKey = GetRoutingKey(envelope.Headers);
                _channel.BasicPublish(
                    exchangeEndpoint.Name,
                    routingKey,
                    properties,
                    envelope.RawMessage.ReadAll());
                break;

            default:
                throw new ArgumentException("Unhandled endpoint type.");
            }

            if (Endpoint.ConfirmationTimeout.HasValue)
            {
                _channel.WaitForConfirmsOrDie(Endpoint.ConfirmationTimeout.Value);
            }
        }
Пример #3
0
        public SilverbackIntegrationLoggerTests()
        {
            _logger = new LoggerSubstitute <SilverbackIntegrationLoggerTests>();

            _integrationLogger =
                new SilverbackIntegrationLogger <SilverbackIntegrationLoggerTests>(
                    _logger,
                    new LogTemplates()
                    .ConfigureAdditionalData <TestConsumerEndpoint>("offset-in")
                    .ConfigureAdditionalData <TestProducerEndpoint>("offset-out"));

            _singleInboundMessageContext = ConsumerPipelineContextHelper.CreateSubstitute(
                new InboundEnvelope(
                    new MemoryStream(),
                    new MessageHeaderCollection
            {
                new MessageHeader(DefaultMessageHeaders.FailedAttempts, 1),
                new MessageHeader(DefaultMessageHeaders.MessageType, "Something.Xy"),
                new MessageHeader(DefaultMessageHeaders.MessageId, "1234")
            },
                    new TestOffset(),
                    new TestConsumerEndpoint("Test"),
                    "TestActual",
                    new Dictionary <string, string>
            {
                ["offset-in"] = "9"
            }));

            _inboundSequenceContext = ConsumerPipelineContextHelper.CreateSubstitute(
                new InboundEnvelope(
                    new MemoryStream(),
                    new MessageHeaderCollection
            {
                new MessageHeader(DefaultMessageHeaders.FailedAttempts, 1),
                new MessageHeader(DefaultMessageHeaders.MessageType, "Something.Xy"),
                new MessageHeader(DefaultMessageHeaders.MessageId, "1234"),
                new MessageHeader(DefaultMessageHeaders.BatchId, "3"),
                new MessageHeader(DefaultMessageHeaders.BatchSize, "10")
            },
                    new TestOffset(),
                    new TestConsumerEndpoint("Test")
            {
                Batch = new BatchSettings
                {
                    Size = 5
                }
            },
                    "TestActual",
                    new Dictionary <string, string>
            {
                ["offset-in"] = "9"
            }));
            var sequence = new BatchSequence("123", _inboundSequenceContext);

            sequence.AddAsync(_inboundSequenceContext.Envelope, null, false);
            _inboundSequenceContext.SetSequence(sequence, true);

            _outboundEnvelope = new RawOutboundEnvelope(
                new MemoryStream(),
                new MessageHeaderCollection
            {
                new MessageHeader(DefaultMessageHeaders.MessageType, "Something.Xy"),
                new MessageHeader(DefaultMessageHeaders.MessageId, "1234")
            },
                new TestProducerEndpoint("Test"),
                null,
                new Dictionary <string, string>
            {
                ["offset-out"] = "9"
            });
        }
Пример #4
0
 public void LogCriticalWithMessageInfo(
     EventId eventId,
     Exception exception,
     string logMessage,
     IRawOutboundEnvelope envelope) =>
 LogWithMessageInfo(LogLevel.Critical, eventId, exception, logMessage, envelope);
Пример #5
0
 public void LogErrorWithMessageInfo(
     EventId eventId,
     string logMessage,
     IRawOutboundEnvelope envelope) =>
 LogWithMessageInfo(LogLevel.Error, eventId, null, logMessage, envelope);
Пример #6
0
 public void LogInformationWithMessageInfo(
     EventId eventId,
     string logMessage,
     IRawOutboundEnvelope envelope) =>
 LogWithMessageInfo(LogLevel.Information, eventId, null, logMessage, envelope);
Пример #7
0
 public QueuedMessage(IRawOutboundEnvelope envelope)
 {
     Envelope = envelope;
     TaskCompletionSource = new TaskCompletionSource<IBrokerMessageIdentifier?>();
 }
Пример #8
0
 public QueuedMessage(IRawOutboundEnvelope envelope)
 {
     Envelope             = envelope;
     TaskCompletionSource = new TaskCompletionSource <IOffset?>();
 }