feat: added RabbitMQ queue from back-end to hook auth for client
This commit is contained in:
parent
06367a3ccd
commit
8c9973e55d
6
JOBot.Backend/Infrastructure/Config/RabbitQueues.cs
Normal file
6
JOBot.Backend/Infrastructure/Config/RabbitQueues.cs
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
namespace JOBot.Backend.Infrastructure.Config;
|
||||||
|
|
||||||
|
public static class RabbitQueues
|
||||||
|
{
|
||||||
|
public const string AuthQueue = "auth";
|
||||||
|
}
|
@ -4,7 +4,7 @@ var builder = WebApplication.CreateBuilder(args);
|
|||||||
|
|
||||||
var startup = new Startup(builder.Configuration);
|
var startup = new Startup(builder.Configuration);
|
||||||
|
|
||||||
startup.ConfigureServices(builder.Services);
|
await startup.ConfigureServices(builder.Services);
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
startup.Configure(app, app.Environment);
|
startup.Configure(app, app.Environment);
|
||||||
|
@ -1,14 +1,19 @@
|
|||||||
|
using System.Text;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Web;
|
|
||||||
using JOBot.Backend.DAL.Context;
|
using JOBot.Backend.DAL.Context;
|
||||||
using JOBot.Backend.DTOs.HeadHunterHook;
|
using JOBot.Backend.DTOs.HeadHunterHook;
|
||||||
using JOBot.Backend.Infrastructure.Config;
|
using JOBot.Backend.Infrastructure.Config;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
using RabbitMQ.Client;
|
||||||
|
|
||||||
namespace JOBot.Backend.Services;
|
namespace JOBot.Backend.Services;
|
||||||
|
|
||||||
public class HeadHunterService(ILogger<HeadHunterService> logger, IOptions<HeadHunterConfig> config, AppDbContext dbContext)
|
public class HeadHunterService(
|
||||||
|
IChannel channel,
|
||||||
|
ILogger<HeadHunterService> logger,
|
||||||
|
IOptions<HeadHunterConfig> config,
|
||||||
|
AppDbContext dbContext)
|
||||||
{
|
{
|
||||||
private readonly HeadHunterConfig _config = config.Value;
|
private readonly HeadHunterConfig _config = config.Value;
|
||||||
|
|
||||||
@ -88,6 +93,14 @@ public class HeadHunterService(ILogger<HeadHunterService> logger, IOptions<HeadH
|
|||||||
await dbContext.SaveChangesAsync();
|
await dbContext.SaveChangesAsync();
|
||||||
|
|
||||||
logger.LogInformation($"User {userId} auth completed!");
|
logger.LogInformation($"User {userId} auth completed!");
|
||||||
|
|
||||||
|
await channel.BasicPublishAsync(
|
||||||
|
string.Empty,
|
||||||
|
RabbitQueues.AuthQueue,
|
||||||
|
Encoding.UTF8.GetBytes(userId.ToString()));
|
||||||
|
|
||||||
|
logger.LogInformation($"RabbitMQ event was created");
|
||||||
|
|
||||||
return Status.Success;
|
return Status.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ using JOBot.Backend.Infrastructure.Config;
|
|||||||
using JOBot.Backend.Services;
|
using JOBot.Backend.Services;
|
||||||
using JOBot.Backend.Services.gRPC;
|
using JOBot.Backend.Services.gRPC;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using RabbitMQ.Client;
|
||||||
|
|
||||||
namespace JOBot.Backend;
|
namespace JOBot.Backend;
|
||||||
|
|
||||||
@ -10,12 +11,20 @@ public class Startup(IConfiguration configuration)
|
|||||||
{
|
{
|
||||||
private IConfiguration Configuration { get; } = configuration;
|
private IConfiguration Configuration { get; } = configuration;
|
||||||
|
|
||||||
public void ConfigureServices(IServiceCollection services)
|
public async Task ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddGrpc();
|
services.AddGrpc();
|
||||||
services.AddGrpcReflection();
|
services.AddGrpcReflection();
|
||||||
services.AddControllers();
|
services.AddControllers();
|
||||||
services.AddLogging();
|
services.AddLogging();
|
||||||
|
|
||||||
|
await using var rabbitMqConnection = await new ConnectionFactory
|
||||||
|
{
|
||||||
|
HostName = "jobot-rabbitmq"
|
||||||
|
}.CreateConnectionAsync();
|
||||||
|
await using var channel = await rabbitMqConnection.CreateChannelAsync();
|
||||||
|
await channel.QueueDeclareAsync(RabbitQueues.AuthQueue, false, false, autoDelete: false);
|
||||||
|
services.AddSingleton(channel);
|
||||||
|
|
||||||
services.AddDbContext<AppDbContext>(options =>
|
services.AddDbContext<AppDbContext>(options =>
|
||||||
options.UseNpgsql(Configuration.GetConnectionString("PostgreSQL")));
|
options.UseNpgsql(Configuration.GetConnectionString("PostgreSQL")));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user