Mq Consumer

This commit is contained in:
Mikhail Trubnikov
2023-09-21 15:21:33 +10:00
parent 096a990669
commit c7acfd153d
12 changed files with 211 additions and 15 deletions

View File

@@ -0,0 +1,39 @@
using Microsoft.Extensions.Logging;
using PARR.BLL.Services.Interfaces;
using PARR.GeneratorTemplates.Settings;
namespace PARR.GeneratorTemplates
{
internal class GeneratorTemplate : IGeneratorTemplate
{
private readonly MqSettings mqSettings;
private readonly IMqService mqService;
private readonly ILogger<GeneratorTemplate> logger;
public GeneratorTemplate(
MqSettings mqSettings,
IMqService mqService,
ILogger<GeneratorTemplate> logger
)
{
this.mqSettings = mqSettings;
this.mqService = mqService;
this.logger = logger;
}
public void Start()
{
mqService.InitConsumer(mqSettings);
mqService.Received += (msg) =>
{
logger.LogInformation($"Привет откуда надо!!! ${msg}");
};
}
public void Stop()
{
}
}
}

View File

@@ -1,16 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using PARR.BLL;
using PARR.DAL;
using PARR.GeneratorTemplates.Settings;
namespace PARR.GeneratorTemplates
{
public static class GeneratorTemplateInstaller
{
//public static void InstallGeneratorTemplateServices(this IServiceCollection services, IConfiguration configuration)
//{
//1
public static void InstallGeneratorTemplateServices(this IServiceCollection services, IConfiguration configuration)
{
services.InstallDalServices(configuration);
services.InstallBllServices(configuration);
var mqSettings = new MqSettings();
configuration.GetSection(nameof(MqSettings)).Bind(mqSettings);
services.AddSingleton(mqSettings);
//add other services
services.AddTransient<IGeneratorTemplate, GeneratorTemplate>();
}
//2
public static IConfigurationBuilder AddGeneratorTemplateConfigurations(this IConfigurationBuilder builder, IServiceCollection services)
{
builder.AddDalConfigurations(services);
return builder;
}
//3
public static void AddGeneratorTemplateSettings(this IServiceCollection services, IConfiguration configuration)
{
services.AddDallSettings(configuration);
}
//}
}
}

View File

@@ -0,0 +1,8 @@
namespace PARR.GeneratorTemplates
{
public interface IGeneratorTemplate
{
void Start();
void Stop();
}
}

View File

@@ -6,4 +6,9 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\PARR.BLL\PARR.BLL.csproj" />
<ProjectReference Include="..\PARR.DAL\PARR.DAL.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,12 @@
using PARR.BLL.Contracts.Interfaces;
namespace PARR.GeneratorTemplates.Settings
{
internal class MqSettings : IMqSettings
{
public string HostName { get; set; } = string.Empty;
public string QueueName { get; set; } = string.Empty;
public string User { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
}
}