Skip to content

Commit

Permalink
Add RabbitMQ and MassTransit dependencies. Configure Continent and Co…
Browse files Browse the repository at this point in the history
…untry consumers
  • Loading branch information
dimitrietataru committed Dec 9, 2024
1 parent 09bee4b commit efdf703
Show file tree
Hide file tree
Showing 18 changed files with 154 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<ItemGroup>
<PackageReference Include="AceCSharp.StructuredAutoMapper" Version="3.0.0" />
<PackageReference Include="CatNip.Infrastructure" Version="3.0.0" />
<PackageReference Include="MassTransit.RabbitMQ" Version="8.3.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
20 changes: 20 additions & 0 deletions src/Ace.Geograpi.Infrastructure/DependencyInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<ContinentCreatedEventConsumer, ContinentCreatedEventConsumerDefinition>();
config.AddConsumer<ContinentUpdatedEventConsumer, ContinentUpdatedEventConsumerDefinition>();
config.AddConsumer<ContinentDeletedEventConsumer, ContinentDeletedEventConsumerDefinition>();

config.AddConsumer<CountryCreatedEventConsumer, CountryCreatedEventConsumerDefinition>();
config.AddConsumer<CountryUpdatedEventConsumer, CountryUpdatedEventConsumerDefinition>();
config.AddConsumer<CountryDeletedEventConsumer, CountryDeletedEventConsumerDefinition>();

config.UsingRabbitMq((context, configure) =>
{
configure.Host(builder.Configuration.GetConnectionString("RabbitMQ"));

configure.ConfigureEndpoints(context);
});
});
}

internal static void AddDatabase(
Expand Down
1 change: 1 addition & 0 deletions src/Ace.Geograpi.Infrastructure/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Ace.Geograpi.Domain.Events.Continents;

namespace Ace.Geograpi.Infrastructure.MessageBus.Consumers.Continents;

internal sealed class ContinentCreatedEventConsumer : IConsumer<ContinentCreatedEvent>
{
public Task Consume(ConsumeContext<ContinentCreatedEvent> context)
{
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Ace.Geograpi.Infrastructure.MessageBus.Consumers.Continents;

internal sealed class ContinentCreatedEventConsumerDefinition

Check warning on line 3 in src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Continents/ContinentCreatedEventConsumerDefinition.cs

View workflow job for this annotation

GitHub Actions / build

'ContinentCreatedEventConsumerDefinition' is an internal class that is apparently never instantiated. If so, remove the code from the assembly. If this class is intended to contain only static members, make it 'static' (Module in Visual Basic). (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1812)
: ConsumerDefinition<ContinentCreatedEventConsumer>
{
public ContinentCreatedEventConsumerDefinition()
{
EndpointName = "geograpi-continent-created";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Ace.Geograpi.Domain.Events.Continents;

namespace Ace.Geograpi.Infrastructure.MessageBus.Consumers.Continents;

internal sealed class ContinentDeletedEventConsumer : IConsumer<ContinentDeletedEvent>

Check warning on line 5 in src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Continents/ContinentDeletedEventConsumer.cs

View workflow job for this annotation

GitHub Actions / build

'ContinentDeletedEventConsumer' is an internal class that is apparently never instantiated. If so, remove the code from the assembly. If this class is intended to contain only static members, make it 'static' (Module in Visual Basic). (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1812)
{
public Task Consume(ConsumeContext<ContinentDeletedEvent> context)
{
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Ace.Geograpi.Infrastructure.MessageBus.Consumers.Continents;

internal sealed class ContinentDeletedEventConsumerDefinition

Check warning on line 3 in src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Continents/ContinentDeletedEventConsumerDefinition.cs

View workflow job for this annotation

GitHub Actions / build

'ContinentDeletedEventConsumerDefinition' is an internal class that is apparently never instantiated. If so, remove the code from the assembly. If this class is intended to contain only static members, make it 'static' (Module in Visual Basic). (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1812)
: ConsumerDefinition<ContinentDeletedEventConsumer>
{
public ContinentDeletedEventConsumerDefinition()
{
EndpointName = "geograpi-continent-deleted";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Ace.Geograpi.Domain.Events.Continents;

namespace Ace.Geograpi.Infrastructure.MessageBus.Consumers.Continents;

internal sealed class ContinentUpdatedEventConsumer : IConsumer<ContinentUpdatedEvent>

Check warning on line 5 in src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Continents/ContinentUpdatedEventConsumer.cs

View workflow job for this annotation

GitHub Actions / build

'ContinentUpdatedEventConsumer' is an internal class that is apparently never instantiated. If so, remove the code from the assembly. If this class is intended to contain only static members, make it 'static' (Module in Visual Basic). (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1812)
{
public Task Consume(ConsumeContext<ContinentUpdatedEvent> context)
{
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Ace.Geograpi.Infrastructure.MessageBus.Consumers.Continents;

internal sealed class ContinentUpdatedEventConsumerDefinition

Check warning on line 3 in src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Continents/ContinentUpdatedEventConsumerDefinition.cs

View workflow job for this annotation

GitHub Actions / build

'ContinentUpdatedEventConsumerDefinition' is an internal class that is apparently never instantiated. If so, remove the code from the assembly. If this class is intended to contain only static members, make it 'static' (Module in Visual Basic). (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1812)
: ConsumerDefinition<ContinentUpdatedEventConsumer>
{
public ContinentUpdatedEventConsumerDefinition()
{
EndpointName = "geograpi-continent-updated";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Ace.Geograpi.Domain.Events.Countries;

namespace Ace.Geograpi.Infrastructure.MessageBus.Consumers.Countries;

internal sealed class CountryCreatedEventConsumer : IConsumer<CountryCreatedEvent>
{
public Task Consume(ConsumeContext<CountryCreatedEvent> context)
{
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Ace.Geograpi.Infrastructure.MessageBus.Consumers.Countries;

internal sealed class CountryCreatedEventConsumerDefinition

Check warning on line 3 in src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Countries/CountryCreatedEventConsumerDefinition.cs

View workflow job for this annotation

GitHub Actions / build

'CountryCreatedEventConsumerDefinition' is an internal class that is apparently never instantiated. If so, remove the code from the assembly. If this class is intended to contain only static members, make it 'static' (Module in Visual Basic). (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1812)
: ConsumerDefinition<CountryCreatedEventConsumer>
{
public CountryCreatedEventConsumerDefinition()
{
EndpointName = "geograpi-country-created";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Ace.Geograpi.Domain.Events.Countries;

namespace Ace.Geograpi.Infrastructure.MessageBus.Consumers.Countries;

internal sealed class CountryDeletedEventConsumer : IConsumer<CountryDeletedEvent>

Check warning on line 5 in src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Countries/CountryDeletedEventConsumer.cs

View workflow job for this annotation

GitHub Actions / build

'CountryDeletedEventConsumer' is an internal class that is apparently never instantiated. If so, remove the code from the assembly. If this class is intended to contain only static members, make it 'static' (Module in Visual Basic). (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1812)
{
public Task Consume(ConsumeContext<CountryDeletedEvent> context)
{
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Ace.Geograpi.Infrastructure.MessageBus.Consumers.Countries;

internal sealed class CountryDeletedEventConsumerDefinition

Check warning on line 3 in src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Countries/CountryDeletedEventConsumerDefinition.cs

View workflow job for this annotation

GitHub Actions / build

'CountryDeletedEventConsumerDefinition' is an internal class that is apparently never instantiated. If so, remove the code from the assembly. If this class is intended to contain only static members, make it 'static' (Module in Visual Basic). (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1812)
: ConsumerDefinition<CountryDeletedEventConsumer>
{
public CountryDeletedEventConsumerDefinition()
{
EndpointName = "geograpi-country-deleted";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Ace.Geograpi.Domain.Events.Countries;

namespace Ace.Geograpi.Infrastructure.MessageBus.Consumers.Countries;

internal sealed class CountryUpdatedEventConsumer : IConsumer<CountryUpdatedEvent>

Check warning on line 5 in src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Countries/CountryUpdatedEventConsumer.cs

View workflow job for this annotation

GitHub Actions / build

'CountryUpdatedEventConsumer' is an internal class that is apparently never instantiated. If so, remove the code from the assembly. If this class is intended to contain only static members, make it 'static' (Module in Visual Basic). (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1812)
{
public Task Consume(ConsumeContext<CountryUpdatedEvent> context)
{
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Ace.Geograpi.Infrastructure.MessageBus.Consumers.Countries;

internal sealed class CountryUpdatedEventConsumerDefinition

Check warning on line 3 in src/Ace.Geograpi.Infrastructure/MessageBus/Consumers/Countries/CountryUpdatedEventConsumerDefinition.cs

View workflow job for this annotation

GitHub Actions / build

'CountryUpdatedEventConsumerDefinition' is an internal class that is apparently never instantiated. If so, remove the code from the assembly. If this class is intended to contain only static members, make it 'static' (Module in Visual Basic). (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1812)
: ConsumerDefinition<CountryUpdatedEventConsumer>
{
public CountryUpdatedEventConsumerDefinition()
{
EndpointName = "geograpi-country-updated";
}
}
3 changes: 2 additions & 1 deletion src/Ace.Geograpi.Web/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -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" ],
Expand Down
3 changes: 2 additions & 1 deletion src/Ace.Geograpi.Web/appsettings.Docker.json
Original file line number Diff line number Diff line change
@@ -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:[email protected]:5672"
},
"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],
Expand Down
3 changes: 2 additions & 1 deletion src/Ace.Geograpi.Web/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"ConnectionStrings": {
"Database": ""
"Database": "",
"RabbitMQ": ""
},
"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],
Expand Down

0 comments on commit efdf703

Please sign in to comment.