Mq Consumer
This commit is contained in:
@@ -15,4 +15,8 @@
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\PARR.GeneratorTemplates\PARR.GeneratorTemplates.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -1,9 +1,26 @@
|
||||
using PARR.GeneratorTemplates;
|
||||
using PARR.GeneratorTemplatesWorker;
|
||||
using Serilog;
|
||||
|
||||
|
||||
IHost host = Host.CreateDefaultBuilder(args)
|
||||
.ConfigureServices(services =>
|
||||
.ConfigureServices((hostContext, services) =>
|
||||
{
|
||||
services.InstallGeneratorTemplateServices(hostContext.Configuration);
|
||||
//hostContext.Configuration.AddGeneratorTemplateConfigurations(services);
|
||||
//services.AddGeneratorTemplateSettings(hostContext.Configuration);
|
||||
|
||||
//services.AddHostedService<Worker>();
|
||||
})
|
||||
//.ConfigureAppConfiguration((hostContext, configBuilder) =>
|
||||
//{
|
||||
//TODO: !!! !!! !!! не смог прикрутить AddGeneratorTemplateConfigurations, не могу прокинуть туда сервисы
|
||||
// configBuilder.AddGeneratorTemplateConfigurations(hostContext.Services);
|
||||
//})
|
||||
.ConfigureServices((hostContext, services) =>
|
||||
{
|
||||
//services.AddGeneratorTemplateSettings(hostContext.Configuration);
|
||||
|
||||
services.AddHostedService<Worker>();
|
||||
})
|
||||
.UseSerilog((hostContext, services, config) =>
|
||||
|
||||
@@ -1,21 +1,34 @@
|
||||
using PARR.GeneratorTemplates;
|
||||
|
||||
namespace PARR.GeneratorTemplatesWorker
|
||||
{
|
||||
public class Worker : BackgroundService
|
||||
{
|
||||
private readonly ILogger<Worker> _logger;
|
||||
private readonly IGeneratorTemplate generatorTemplate;
|
||||
|
||||
public Worker(ILogger<Worker> logger)
|
||||
public Worker(ILogger<Worker> logger, IGeneratorTemplate generatorTemplate)
|
||||
{
|
||||
_logger = logger;
|
||||
this.generatorTemplate = generatorTemplate;
|
||||
}
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
|
||||
await Task.Delay(1000, stoppingToken);
|
||||
}
|
||||
// todo: обернуть в таск?
|
||||
generatorTemplate.Start();
|
||||
//while (!stoppingToken.IsCancellationRequested)
|
||||
//{
|
||||
// _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
|
||||
// await Task.Delay(1000, stoppingToken);
|
||||
//}
|
||||
}
|
||||
|
||||
public override Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
generatorTemplate.Stop();
|
||||
|
||||
return base.StopAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,5 +4,8 @@
|
||||
"Default": "Information",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"MqSettings": {
|
||||
"HostName": "10.99.253.216"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,5 +22,11 @@
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"MqSettings": {
|
||||
"HostName": "parr-rabbitmq",
|
||||
"QueueName": "parr-generate-templates",
|
||||
"User": "generate_templates_worker",
|
||||
"Password": "Dhgdf%d&609sssa"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user