예제 #1
0
        public void Setup()
        {
            _sink = new KafkaSink(new JsonFormatter(), new MockKafkaProducer(), new StringWriterPoolOptions {
                Amount = Amount
            });

            _events = Enumerable.Range(0, N)
                      .Select(x => new LogEvent(DateTimeOffset.UtcNow, LogEventLevel.Information, null,
                                                new MessageTemplate("Info text", new List <MessageTemplateToken>()),
                                                new List <LogEventProperty>()))
                      .ToList();
        }
        public static LoggerConfiguration Kafka(
            this LoggerSinkConfiguration loggerConfiguration,
            KafkaSinkOptions options)
        {
            Contract.Requires(loggerConfiguration != null);
            Contract.Requires(options != null);
            Contract.Ensures(Contract.Result <LoggerConfiguration>() != null);

            var kafkaClient = new KafkaClient(options);
            var kafkaSink   = new KafkaSink(kafkaClient, options);
            var result      = loggerConfiguration.Sink(kafkaSink);

            Contract.Assume(result != null);
            return(result);
        }
예제 #3
0
        public void CanSendEmptyMessageBatch()
        {
            // Given
            var options = new KafkaSinkOptions("topic", new[] { new Uri("http://sample") });
            var kafkaClient = new KafkaClient(options);
            var systemUnderTest = new KafkaSink(kafkaClient, options);
            var logEvents = new LogEvent[0];
            
            // When 
            var result = systemUnderTest.EmitBatchInternalAsync(logEvents);

            // Then
            Assert.IsTrue(result.IsCompleted);
            Assert.IsFalse(result.IsFaulted);
        }
예제 #4
0
        /// <summary>
        /// Adds a sink that writes log events to a Kafka topic in the broker endpoints.
        /// </summary>
        /// <param name="loggerConfiguration">The logger configuration.</param>
        /// <param name="batchSizeLimit">The maximum number of events to include in a single batch.</param>
        /// <param name="period">The time in seconds to wait between checking for event batches.</param>
        /// <param name="brokers">The list of brokers separated by comma.</param>
        /// <param name="topic">The topic name.</param>
        /// <returns></returns>
        public static LoggerConfiguration Kafka(
            this LoggerSinkConfiguration loggerConfiguration,
            int batchSizeLimit,
            int period,
            string brokers,
            string topic)
        {
            var sink = new KafkaSink(
                batchSizeLimit,
                period,
                brokers,
                topic);

            return(loggerConfiguration.Sink(sink));
        }
예제 #5
0
        public void CanSendEmptyMessageBatch()
        {
            // Given
            var options         = new KafkaSinkOptions("topic", new[] { new Uri("http://sample") });
            var kafkaClient     = new KafkaClient(options);
            var systemUnderTest = new KafkaSink(kafkaClient, options);
            var logEvents       = new LogEvent[0];

            // When
            var result = systemUnderTest.EmitBatchInternalAsync(logEvents);

            // Then
            Assert.IsTrue(result.IsCompleted);
            Assert.IsFalse(result.IsFaulted);
        }