Ejemplo n.º 1
0
        public void Subscribe(IEnumerable <string> topics)
        {
            Logger.InformationStructured(new
            {
                LogSource  = nameof(Subscribe),
                LogData    = topics,
                LogMessage = "Subscribing to topics."
            });

            ConfluentKafkaConsumer.Subscribe(topics);
        }
Ejemplo n.º 2
0
        public async Task <CommittedOffsets> CommitAsync(
            IEnumerable <TopicPartitionOffset> topicPartitionOffsets)
        {
            var(executionTimeMs, commitReport) =
                await ConfluentKafkaConsumer.CommitAsync(topicPartitionOffsets).Measure();

            Logger.InformationStructured(new
            {
                LogSource  = nameof(CommitAsync),
                LogData    = commitReport,
                LogMessage = $"CommitAsync execution time: {executionTimeMs} ms.",
            });

            return(commitReport);
        }
Ejemplo n.º 3
0
        public async Task <CommittedOffsets> CommitAsync(
            Message <string, TMessage> message)
        {
            var(executionTimeMs, commitReport) =
                await ConfluentKafkaConsumer.CommitAsync(message).Measure();

            Logger.InformationStructured(new
            {
                LogSource  = nameof(CommitAsync),
                LogData    = commitReport,
                LogMessage = $"CommitAsync execution time: {executionTimeMs} ms.",
            });

            return(commitReport);
        }
Ejemplo n.º 4
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                Logger.InformationStructured(new
                {
                    LogSource  = nameof(Dispose),
                    LogMessage = $"Disposing {nameof(ConfluentKafkaConsumer)}."
                });

                ConfluentKafkaConsumer?.Dispose();

                Logger.InformationStructured(new
                {
                    LogSource  = nameof(Dispose),
                    LogMessage = $"{nameof(ConfluentKafkaConsumer)} successfully disposed."
                });
            }
        }
Ejemplo n.º 5
0
        public void StartPolling()
        {
            Logger.InformationStructured(new
            {
                LogSource  = nameof(StartPolling),
                LogMessage = "Started polling for messages."
            });

            while (!CancellationToken.IsCancellationRequested)
            {
                ConfluentKafkaConsumer.Poll(
                    TimeSpan.FromMilliseconds(ConsumerSettings.PollIntervalMs));
            }

            Logger.InformationStructured(new
            {
                LogSource  = nameof(StartPolling),
                LogMessage = "Polling stopped gracefully."
            });
        }
Ejemplo n.º 6
0
        protected virtual void OnPartitionsAssigned(
            object sender,
            List <TopicPartition> topicPartitionsToAssign)
        {
            Logger.InformationStructured(new
            {
                LogSource  = nameof(OnPartitionsAssigned),
                LogData    = topicPartitionsToAssign,
                LogSender  = sender.ToString(),
                LogMessage = "Assigning topic partitions."
            });

            ConfluentKafkaConsumer.Assign(topicPartitionsToAssign);

            Logger.InformationStructured(new
            {
                LogSource  = nameof(OnPartitionsAssigned),
                LogData    = topicPartitionsToAssign,
                LogSender  = sender.ToString(),
                LogMessage = "Topic partitions assigned successfully."
            });
        }
Ejemplo n.º 7
0
        protected virtual void OnPartitionsRevoked(
            object sender,
            List <TopicPartition> revokedTopicPartitions)
        {
            Logger.InformationStructured(new
            {
                LogSource  = nameof(OnPartitionsRevoked),
                LogData    = revokedTopicPartitions,
                LogSender  = sender.ToString(),
                LogMessage = "Revoking topic partitions."
            });

            ConfluentKafkaConsumer.Unassign();

            Logger.InformationStructured(new
            {
                LogSource  = nameof(OnPartitionsRevoked),
                LogData    = revokedTopicPartitions,
                LogSender  = sender.ToString(),
                LogMessage = "Topic partitions revoked successfully."
            });
        }