40 lines
1.1 KiB
C#
40 lines
1.1 KiB
C#
|
namespace Cloud.Services
|
|||
|
{
|
|||
|
public class BackgroundWorkerService : BackgroundService
|
|||
|
{
|
|||
|
public readonly ILogger<BackgroundWorkerService> _logger;
|
|||
|
private readonly ConsumerService _consumerService;
|
|||
|
|
|||
|
public BackgroundWorkerService(ILogger<BackgroundWorkerService> 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}");
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|