From fed96d5b86b42399c3921a1193e85f60a2d35b0c Mon Sep 17 00:00:00 2001 From: mfnefd Date: Tue, 19 Nov 2024 23:42:12 +0400 Subject: [PATCH] =?UTF-8?q?del:=20=D1=81=D0=B5=D1=80=D0=B2=D0=B8=D1=81?= =?UTF-8?q?=D1=8B=20=D0=B1=D1=80=D0=BE=D0=BA=D0=B5=D1=80=D0=B0=20=D0=BE?= =?UTF-8?q?=D0=BD=D0=B8=20=D1=83=D0=B6=D0=B5=20=D0=B5=D1=81=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cloud/Services/BackgroundWorkerService.cs | 39 ----------------- Cloud/Services/ConsumerService.cs | 51 ----------------------- Cloud/Services/ProducerService.cs | 33 --------------- 3 files changed, 123 deletions(-) delete mode 100644 Cloud/Services/BackgroundWorkerService.cs delete mode 100644 Cloud/Services/ConsumerService.cs delete mode 100644 Cloud/Services/ProducerService.cs diff --git a/Cloud/Services/BackgroundWorkerService.cs b/Cloud/Services/BackgroundWorkerService.cs deleted file mode 100644 index f7fbf34..0000000 --- a/Cloud/Services/BackgroundWorkerService.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace Cloud.Services -{ - public class BackgroundWorkerService : BackgroundService - { - public readonly ILogger _logger; - private readonly ConsumerService _consumerService; - - public BackgroundWorkerService(ILogger logger, ConsumerService consumer) - { - _logger = logger; - _consumerService = consumer; - } - - //Backghround Service, This will run continuously - protected override async Task ExecuteAsync(CancellationToken stoppingToken) - { - try - { - while (!stoppingToken.IsCancellationRequested) - { - //_logger.LogInformation("Background Service is Runing at : {time}", DateTimeOffset.Now); - - string request = await _consumerService.WaitMessage("ValvesHeatersRequest"); //Consume the Kafka Message - - //After Consume the Order Request Can process the order - if (!string.IsNullOrEmpty(request)) - _logger.LogInformation("Valves-Heaters Request : {value}", request); - - - await Task.Delay(1000, stoppingToken); - } - } - catch (Exception ex) - { - _logger.LogError($"BackgroundWorkerService - Exception {ex}"); - } - } - } -} diff --git a/Cloud/Services/ConsumerService.cs b/Cloud/Services/ConsumerService.cs deleted file mode 100644 index 82d5bb2..0000000 --- a/Cloud/Services/ConsumerService.cs +++ /dev/null @@ -1,51 +0,0 @@ -using Confluent.Kafka; - -namespace Cloud.Services -{ - public class ConsumerService - { - private IConsumer _consumer; - private ConsumerConfig consumerConfig; - public ConsumerService(IConfiguration configuration) - { - consumerConfig = new ConsumerConfig - { - BootstrapServers = configuration["Kafka:BootstrapServers"], - GroupId = configuration["Kafka:GroupId"], - AutoOffsetReset = AutoOffsetReset.Earliest, - }; - - _consumer = new ConsumerBuilder(consumerConfig).Build(); - } - - //Consume Method - public async TaskWaitMessage(string topic) - { - try - { - _consumer.Subscribe(topic); - - var consumeResult = _consumer.Consume(TimeSpan.FromMilliseconds(1000)); - - if (consumeResult != null) - { - return consumeResult.Message.Value; - } - else - { - //No message received from Kafka within the specified timeout. - } - return ""; - - } - catch (Exception ex) - { - return ""; - } - finally - { - _consumer.Close(); - } - } - } -} diff --git a/Cloud/Services/ProducerService.cs b/Cloud/Services/ProducerService.cs deleted file mode 100644 index 073bdc6..0000000 --- a/Cloud/Services/ProducerService.cs +++ /dev/null @@ -1,33 +0,0 @@ -using Confluent.Kafka; - -namespace Cloud.Services -{ - public class ProducerService - { - private readonly IProducer _producer; - - public ProducerService(IConfiguration configuration) - { - var producerConfig = new ProducerConfig - { - BootstrapServers = configuration["Kafka:BootstrapServers"] - }; - - //Build the Producer - _producer = new ProducerBuilder(producerConfig).Build(); - } - - //Method for Produce the Message to Kafka Topic - public async Task ProduceMessageAsync(string topic, string value) - { - var kafkaMessage = new Message - { - Key = Guid.NewGuid().ToString(), - Value = value - }; - - //Produce the Message - await _producer.ProduceAsync(topic, kafkaMessage); - } - } -}