From efdf703640f53d42bba484f15dfa04a2e2722947 Mon Sep 17 00:00:00 2001 From: Dimitrie Tataru Date: Mon, 9 Dec 2024 16:15:39 +0200 Subject: [PATCH] Add RabbitMQ and MassTransit dependencies. Configure Continent and Country consumers --- .../Ace.Geograpi.Infrastructure.csproj | 1 + .../DependencyInjection.cs | 20 +++++++++++++++++++ .../GlobalUsings.cs | 1 + .../ContinentCreatedEventConsumer.cs | 11 ++++++++++ ...ContinentCreatedEventConsumerDefinition.cs | 10 ++++++++++ .../ContinentDeletedEventConsumer.cs | 11 ++++++++++ ...ContinentDeletedEventConsumerDefinition.cs | 10 ++++++++++ .../ContinentUpdatedEventConsumer.cs | 11 ++++++++++ ...ContinentUpdatedEventConsumerDefinition.cs | 10 ++++++++++ .../Countries/CountryCreatedEventConsumer.cs | 11 ++++++++++ .../CountryCreatedEventConsumerDefinition.cs | 10 ++++++++++ .../Countries/CountryDeletedEventConsumer.cs | 11 ++++++++++ .../CountryDeletedEventConsumerDefinition.cs | 10 ++++++++++ .../Countries/CountryUpdatedEventConsumer.cs | 11 ++++++++++ .../CountryUpdatedEventConsumerDefinition.cs | 10 ++++++++++ .../appsettings.Development.json | 3 ++- src/Ace.Geograpi.Web/appsettings.Docker.json | 3 ++- src/Ace.Geograpi.Web/appsettings.json | 3 ++- 18 files changed, 154 insertions(+), 3 deletions(-) create mode 100644 src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Continents/ContinentCreatedEventConsumer.cs create mode 100644 src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Continents/ContinentCreatedEventConsumerDefinition.cs create mode 100644 src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Continents/ContinentDeletedEventConsumer.cs create mode 100644 src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Continents/ContinentDeletedEventConsumerDefinition.cs create mode 100644 src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Continents/ContinentUpdatedEventConsumer.cs create mode 100644 src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Continents/ContinentUpdatedEventConsumerDefinition.cs create mode 100644 src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Countries/CountryCreatedEventConsumer.cs create mode 100644 src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Countries/CountryCreatedEventConsumerDefinition.cs create mode 100644 src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Countries/CountryDeletedEventConsumer.cs create mode 100644 src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Countries/CountryDeletedEventConsumerDefinition.cs create mode 100644 src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Countries/CountryUpdatedEventConsumer.cs create mode 100644 src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Countries/CountryUpdatedEventConsumerDefinition.cs diff --git a/src/Ace.Geograpi.Infrastructure/Ace.Geograpi.Infrastructure.csproj b/src/Ace.Geograpi.Infrastructure/Ace.Geograpi.Infrastructure.csproj index 93d8aa1..861581e 100644 --- a/src/Ace.Geograpi.Infrastructure/Ace.Geograpi.Infrastructure.csproj +++ b/src/Ace.Geograpi.Infrastructure/Ace.Geograpi.Infrastructure.csproj @@ -11,6 +11,7 @@ + runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/Ace.Geograpi.Infrastructure/DependencyInjection.cs b/src/Ace.Geograpi.Infrastructure/DependencyInjection.cs index 7be6ca8..cacd87f 100644 --- a/src/Ace.Geograpi.Infrastructure/DependencyInjection.cs +++ b/src/Ace.Geograpi.Infrastructure/DependencyInjection.cs @@ -5,6 +5,8 @@ using Ace.Geograpi.Infrastructure.Mappers; using Ace.Geograpi.Infrastructure.Mappers.Root; using Ace.Geograpi.Infrastructure.Mappers.Traceable; +using Ace.Geograpi.Infrastructure.MessageBus.Consumers.Continents; +using Ace.Geograpi.Infrastructure.MessageBus.Consumers.Countries; using Ace.Geograpi.Infrastructure.Repositories; namespace Ace.Geograpi.Infrastructure; @@ -16,6 +18,24 @@ public static void AddInfrastructure(this IHostApplicationBuilder builder) builder.Services.AddDatabase(builder.Configuration, builder.Environment); builder.Services.AddMappers(); builder.Services.AddRepositories(); + + builder.Services.AddMassTransit(config => + { + config.AddConsumer(); + config.AddConsumer(); + config.AddConsumer(); + + config.AddConsumer(); + config.AddConsumer(); + config.AddConsumer(); + + config.UsingRabbitMq((context, configure) => + { + configure.Host(builder.Configuration.GetConnectionString("RabbitMQ")); + + configure.ConfigureEndpoints(context); + }); + }); } internal static void AddDatabase( diff --git a/src/Ace.Geograpi.Infrastructure/GlobalUsings.cs b/src/Ace.Geograpi.Infrastructure/GlobalUsings.cs index a1ebf45..326e4ff 100644 --- a/src/Ace.Geograpi.Infrastructure/GlobalUsings.cs +++ b/src/Ace.Geograpi.Infrastructure/GlobalUsings.cs @@ -1,5 +1,6 @@ global using Ace.CSharp.StructuredAutoMapper; global using AutoMapper; +global using MassTransit; global using Microsoft.EntityFrameworkCore; global using Microsoft.EntityFrameworkCore.Metadata.Builders; global using Microsoft.Extensions.Configuration; diff --git a/src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Continents/ContinentCreatedEventConsumer.cs b/src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Continents/ContinentCreatedEventConsumer.cs new file mode 100644 index 0000000..b00bace --- /dev/null +++ b/src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Continents/ContinentCreatedEventConsumer.cs @@ -0,0 +1,11 @@ +using Ace.Geograpi.Domain.Events.Continents; + +namespace Ace.Geograpi.Infrastructure.MessageBus.Consumers.Continents; + +internal sealed class ContinentCreatedEventConsumer : IConsumer +{ + public Task Consume(ConsumeContext context) + { + throw new NotImplementedException(); + } +} diff --git a/src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Continents/ContinentCreatedEventConsumerDefinition.cs b/src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Continents/ContinentCreatedEventConsumerDefinition.cs new file mode 100644 index 0000000..b5040cf --- /dev/null +++ b/src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Continents/ContinentCreatedEventConsumerDefinition.cs @@ -0,0 +1,10 @@ +namespace Ace.Geograpi.Infrastructure.MessageBus.Consumers.Continents; + +internal sealed class ContinentCreatedEventConsumerDefinition + : ConsumerDefinition +{ + public ContinentCreatedEventConsumerDefinition() + { + EndpointName = "geograpi-continent-created"; + } +} diff --git a/src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Continents/ContinentDeletedEventConsumer.cs b/src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Continents/ContinentDeletedEventConsumer.cs new file mode 100644 index 0000000..182bf17 --- /dev/null +++ b/src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Continents/ContinentDeletedEventConsumer.cs @@ -0,0 +1,11 @@ +using Ace.Geograpi.Domain.Events.Continents; + +namespace Ace.Geograpi.Infrastructure.MessageBus.Consumers.Continents; + +internal sealed class ContinentDeletedEventConsumer : IConsumer +{ + public Task Consume(ConsumeContext context) + { + throw new NotImplementedException(); + } +} diff --git a/src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Continents/ContinentDeletedEventConsumerDefinition.cs b/src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Continents/ContinentDeletedEventConsumerDefinition.cs new file mode 100644 index 0000000..bbc7228 --- /dev/null +++ b/src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Continents/ContinentDeletedEventConsumerDefinition.cs @@ -0,0 +1,10 @@ +namespace Ace.Geograpi.Infrastructure.MessageBus.Consumers.Continents; + +internal sealed class ContinentDeletedEventConsumerDefinition + : ConsumerDefinition +{ + public ContinentDeletedEventConsumerDefinition() + { + EndpointName = "geograpi-continent-deleted"; + } +} diff --git a/src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Continents/ContinentUpdatedEventConsumer.cs b/src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Continents/ContinentUpdatedEventConsumer.cs new file mode 100644 index 0000000..c3eb77b --- /dev/null +++ b/src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Continents/ContinentUpdatedEventConsumer.cs @@ -0,0 +1,11 @@ +using Ace.Geograpi.Domain.Events.Continents; + +namespace Ace.Geograpi.Infrastructure.MessageBus.Consumers.Continents; + +internal sealed class ContinentUpdatedEventConsumer : IConsumer +{ + public Task Consume(ConsumeContext context) + { + throw new NotImplementedException(); + } +} diff --git a/src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Continents/ContinentUpdatedEventConsumerDefinition.cs b/src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Continents/ContinentUpdatedEventConsumerDefinition.cs new file mode 100644 index 0000000..408269e --- /dev/null +++ b/src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Continents/ContinentUpdatedEventConsumerDefinition.cs @@ -0,0 +1,10 @@ +namespace Ace.Geograpi.Infrastructure.MessageBus.Consumers.Continents; + +internal sealed class ContinentUpdatedEventConsumerDefinition + : ConsumerDefinition +{ + public ContinentUpdatedEventConsumerDefinition() + { + EndpointName = "geograpi-continent-updated"; + } +} diff --git a/src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Countries/CountryCreatedEventConsumer.cs b/src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Countries/CountryCreatedEventConsumer.cs new file mode 100644 index 0000000..a647945 --- /dev/null +++ b/src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Countries/CountryCreatedEventConsumer.cs @@ -0,0 +1,11 @@ +using Ace.Geograpi.Domain.Events.Countries; + +namespace Ace.Geograpi.Infrastructure.MessageBus.Consumers.Countries; + +internal sealed class CountryCreatedEventConsumer : IConsumer +{ + public Task Consume(ConsumeContext context) + { + throw new NotImplementedException(); + } +} diff --git a/src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Countries/CountryCreatedEventConsumerDefinition.cs b/src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Countries/CountryCreatedEventConsumerDefinition.cs new file mode 100644 index 0000000..c7cd7a0 --- /dev/null +++ b/src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Countries/CountryCreatedEventConsumerDefinition.cs @@ -0,0 +1,10 @@ +namespace Ace.Geograpi.Infrastructure.MessageBus.Consumers.Countries; + +internal sealed class CountryCreatedEventConsumerDefinition + : ConsumerDefinition +{ + public CountryCreatedEventConsumerDefinition() + { + EndpointName = "geograpi-country-created"; + } +} diff --git a/src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Countries/CountryDeletedEventConsumer.cs b/src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Countries/CountryDeletedEventConsumer.cs new file mode 100644 index 0000000..24d50b8 --- /dev/null +++ b/src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Countries/CountryDeletedEventConsumer.cs @@ -0,0 +1,11 @@ +using Ace.Geograpi.Domain.Events.Countries; + +namespace Ace.Geograpi.Infrastructure.MessageBus.Consumers.Countries; + +internal sealed class CountryDeletedEventConsumer : IConsumer +{ + public Task Consume(ConsumeContext context) + { + throw new NotImplementedException(); + } +} diff --git a/src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Countries/CountryDeletedEventConsumerDefinition.cs b/src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Countries/CountryDeletedEventConsumerDefinition.cs new file mode 100644 index 0000000..91de205 --- /dev/null +++ b/src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Countries/CountryDeletedEventConsumerDefinition.cs @@ -0,0 +1,10 @@ +namespace Ace.Geograpi.Infrastructure.MessageBus.Consumers.Countries; + +internal sealed class CountryDeletedEventConsumerDefinition + : ConsumerDefinition +{ + public CountryDeletedEventConsumerDefinition() + { + EndpointName = "geograpi-country-deleted"; + } +} diff --git a/src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Countries/CountryUpdatedEventConsumer.cs b/src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Countries/CountryUpdatedEventConsumer.cs new file mode 100644 index 0000000..cd52e89 --- /dev/null +++ b/src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Countries/CountryUpdatedEventConsumer.cs @@ -0,0 +1,11 @@ +using Ace.Geograpi.Domain.Events.Countries; + +namespace Ace.Geograpi.Infrastructure.MessageBus.Consumers.Countries; + +internal sealed class CountryUpdatedEventConsumer : IConsumer +{ + public Task Consume(ConsumeContext context) + { + throw new NotImplementedException(); + } +} diff --git a/src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Countries/CountryUpdatedEventConsumerDefinition.cs b/src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Countries/CountryUpdatedEventConsumerDefinition.cs new file mode 100644 index 0000000..ddeff57 --- /dev/null +++ b/src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Countries/CountryUpdatedEventConsumerDefinition.cs @@ -0,0 +1,10 @@ +namespace Ace.Geograpi.Infrastructure.MessageBus.Consumers.Countries; + +internal sealed class CountryUpdatedEventConsumerDefinition + : ConsumerDefinition +{ + public CountryUpdatedEventConsumerDefinition() + { + EndpointName = "geograpi-country-updated"; + } +} diff --git a/src/Ace.Geograpi.Web/appsettings.Development.json b/src/Ace.Geograpi.Web/appsettings.Development.json index 50b7ef4..8329757 100644 --- a/src/Ace.Geograpi.Web/appsettings.Development.json +++ b/src/Ace.Geograpi.Web/appsettings.Development.json @@ -1,6 +1,7 @@ { "ConnectionStrings": { - "Database": "Host=localhost;Port=5432;Database=geograpi;Username=postgres;Password=postgres" + "Database": "Host=localhost;Port=5432;Database=geograpi;Username=postgres;Password=postgres", + "RabbitMQ": "amqp://guest:guest@localhost:5672" }, "Serilog": { "Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ], diff --git a/src/Ace.Geograpi.Web/appsettings.Docker.json b/src/Ace.Geograpi.Web/appsettings.Docker.json index 04bd27a..39ffbaf 100644 --- a/src/Ace.Geograpi.Web/appsettings.Docker.json +++ b/src/Ace.Geograpi.Web/appsettings.Docker.json @@ -1,7 +1,8 @@ { "ConnectionStrings": { "Database": "Host=ace.geograpi.db;Port=5432;Database=geograpi;Username=postgres;Password=postgres", - "_Database": "Host=localhost;Port=5432;Database=geograpi;Username=postgres;Password=postgres" + "_Database": "Host=localhost;Port=5432;Database=geograpi;Username=postgres;Password=postgres", + "RabbitMQ": "amqp://guest:guest@ace.geograpi.rabbitmq:5672" }, "Serilog": { "Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ], diff --git a/src/Ace.Geograpi.Web/appsettings.json b/src/Ace.Geograpi.Web/appsettings.json index a43956a..75eaa28 100644 --- a/src/Ace.Geograpi.Web/appsettings.json +++ b/src/Ace.Geograpi.Web/appsettings.json @@ -1,6 +1,7 @@ { "ConnectionStrings": { - "Database": "" + "Database": "", + "RabbitMQ": "" }, "Serilog": { "Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],