Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(service): use in-memory transport instead of rabbitmq #602

Merged
merged 4 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,4 @@ POSTGRES_PASSWORD=supersecret
POSTGRES_DB=Dialogporten
DB_CONNECTION_STRING=Server=dialogporten-postgres;Port=5432;Database=${POSTGRES_DB};User ID=${POSTGRES_USER};Password=${POSTGRES_PASSWORD};

RABBITMQ_USER=guest
RABBITMQ_PASSWORD=guest
RABBITMQ_HOST=dialogporten-rabbitmq

COMPOSE_PROJECT_NAME=digdir
2 changes: 0 additions & 2 deletions .github/workflows/action-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ jobs:
imageName: cdc
- dockerfile: ./src/Digdir.Domain.Dialogporten.Infrastructure/MigrationBundle.dockerfile
imageName: migration-bundle
- dockerfile: ./RabbitMq/Dockerfile
imageName: rabbitmq

permissions:
contents: read
Expand Down
8 changes: 0 additions & 8 deletions RabbitMq/Dockerfile

This file was deleted.

1 change: 0 additions & 1 deletion RabbitMq/enabled_plugins

This file was deleted.

24 changes: 0 additions & 24 deletions docker-compose-no-webapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,6 @@ services:
interval: 2s
timeout: 20s
retries: 5

dialogporten-rabbitmq:
build:
context: .
dockerfile: RabbitMq/Dockerfile
restart: always
ports:
- "5672:5672"
- "15672:15672"
healthcheck:
test: [ "CMD-SHELL", "rabbitmq-diagnostics check_running" ]
interval: 5s
timeout: 20s
retries: 5

dialogporten-redis:
image: redis:6.0-alpine
Expand All @@ -50,14 +36,9 @@ services:
depends_on:
dialogporten-postgres:
condition: service_healthy
dialogporten-rabbitmq:
condition: service_healthy
environment:
- Infrastructure:DialogDbConnectionString=${DB_CONNECTION_STRING}
- ASPNETCORE_ENVIRONMENT=Development
- RabbitMq:Host=${RABBITMQ_HOST}
- RabbitMq:Username=${RABBITMQ_USERNAME}
- RabbitMq:Password=${RABBITMQ_PASSWORD}

dialogporten-cdc:
build:
Expand All @@ -67,14 +48,9 @@ services:
depends_on:
dialogporten-postgres:
condition: service_healthy
dialogporten-rabbitmq:
condition: service_healthy
environment:
- ASPNETCORE_ENVIRONMENT=Development
- Infrastructure:DialogDbConnectionString=${DB_CONNECTION_STRING}
- ReplicationSlotName=outboxmessage_replication_slot
- PublicationName=outboxmessage_publication
- TableName=OutboxMessage
- RabbitMq:Host=${RABBITMQ_HOST}
- RabbitMq:Username=${RABBITMQ_USERNAME}
- RabbitMq:Password=${RABBITMQ_PASSWORD}
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ services:
environment:
- Infrastructure:Redis:ConnectionString=dialogporten-redis:6379
- Infrastructure:DialogDbConnectionString=${DB_CONNECTION_STRING}
- Application:Dialogporten:BaseUri=http://localhost:7214
- Serilog__WriteTo__0__Name=Console
- Serilog__MinimumLevel__Default=Debug
- ASPNETCORE_URLS=http://+:8080
Expand Down
1 change: 0 additions & 1 deletion enabled_plugins

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UserSecretsId>750256a4-f332-4783-8802-8a7d9566f9ca</UserSecretsId>
<UserSecretsId>750256a4-f332-4783-8802-8a7d9566f9ca</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.10.4" />
<PackageReference Include="MassTransit.RabbitMQ" Version="8.2.0" />
<PackageReference Include="MassTransit" Version="8.2.0" />
<PackageReference Include="Npgsql" Version="8.0.2" />
<PackageReference Include="RabbitMQ.Client" Version="6.8.1" />
<PackageReference Include="Microsoft.Azure.AppConfiguration.AspNetCore" Version="7.1.0" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
<PackageReference Include="Serilog.Sinks.ApplicationInsights" Version="4.0.0" />
Expand All @@ -23,4 +22,4 @@
<ProjectReference Include="..\Digdir.Domain.Dialogporten.Domain\Digdir.Domain.Dialogporten.Domain.csproj" />
</ItemGroup>

</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@ public async Task Send(OutboxMessage outboxMessage, CancellationToken cancellati
var endpoint = await _sender.GetSendEndpoint(new Uri("exchange:Digdir.Domain.Dialogporten.Service"));
await endpoint.Send(
outboxMessage,
context =>
{
if (context is not RabbitMqSendContext rabbitMqSendContext)
{
throw new ArgumentException("The context is not a RabbitMQ send context.", nameof(context));
}

rabbitMqSendContext.Mandatory = true;
},
cancellationToken);
}
}
18 changes: 11 additions & 7 deletions src/Digdir.Domain.Dialogporten.ChangeDataCapture/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using Microsoft.ApplicationInsights.Extensibility;
using Serilog;

// TODO: Configure RabbitMQ connection settings and endpoint exchange
// TODO: Configure Azure Service Bus connection settings and endpoint exchange
// TODO: Configure Postgres connection settings
// TODO: Improve exceptions thrown in this assembly

Expand Down Expand Up @@ -59,15 +59,19 @@ static void BuildAndRun(string[] args)
.AddHostedService<CdcBackgroundHandler>()
.AddMassTransit(x =>
{
x.UsingRabbitMq((context, cfg) =>
var useInMemoryTransport = builder.Configuration.GetValue<bool>("MassTransit:UseInMemoryTransport");

if (useInMemoryTransport)
{
const string rabbitMqSection = "RabbitMq";
cfg.Host(builder.Configuration[$"{rabbitMqSection}:Host"], "/", h =>
x.UsingInMemory((context, cfg) =>
{
h.Username(builder.Configuration[$"{rabbitMqSection}:Username"]);
h.Password(builder.Configuration[$"{rabbitMqSection}:Password"]);
cfg.ConfigureEndpoints(context);
});
});
}
else
{
// todo: Configure for using Azure Service Bus
}
})
.AddSingleton(_ => new PostgresCdcSSubscriptionOptions
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
"ReplicationSlotName": "outboxmessage_replication_slot",
"PublicationName": "outboxmessage_publication",
"TableName": "OutboxMessage",
"RabbitMq": {
"Host": "localhost",
"Username": "guest",
"Password": "guest"
"MassTransit": {
"UseInMemoryTransport": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MassTransit.RabbitMQ" Version="8.2.0" />
<PackageReference Include="RabbitMQ.Client" Version="6.8.1" />
<PackageReference Include="MassTransit" Version="8.2.0" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
<PackageReference Include="Serilog.Sinks.ApplicationInsights" Version="4.0.0"/>
<PackageReference Include="Serilog.Sinks.ApplicationInsights" Version="4.0.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Digdir.Domain.Dialogporten.Application\Digdir.Domain.Dialogporten.Application.csproj"/>
<ProjectReference Include="..\Digdir.Domain.Dialogporten.Infrastructure\Digdir.Domain.Dialogporten.Infrastructure.csproj"/>
<ProjectReference Include="..\Digdir.Domain.Dialogporten.Application\Digdir.Domain.Dialogporten.Application.csproj" />
<ProjectReference Include="..\Digdir.Domain.Dialogporten.Infrastructure\Digdir.Domain.Dialogporten.Infrastructure.csproj" />
</ItemGroup>

</Project>
33 changes: 12 additions & 21 deletions src/Digdir.Domain.Dialogporten.Service/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using Digdir.Domain.Dialogporten.Service;

// TODO: Add AppConfiguration and key vault
// TODO: Configure RabbitMQ connection settings
// TODO: Configure Service bus connection settings
// TODO: Configure Postgres connection settings
// TODO: Improve exceptions thrown in this assembly

Expand Down Expand Up @@ -60,29 +60,20 @@ static void BuildAndRun(string[] args)
.AddMassTransit(x =>
{
x.AddConsumers(thisAssembly);
x.UsingRabbitMq((context, cfg) =>

var useInMemoryTransport = builder.Configuration.GetValue<bool>("MassTransit:UseInMemoryTransport");

if (useInMemoryTransport)
{
const string rabbitMqSection = "RabbitMq";
cfg.Host(builder.Configuration[$"{rabbitMqSection}:Host"], "/", h =>
x.UsingInMemory((context, cfg) =>
{
h.Username(builder.Configuration[$"{rabbitMqSection}:Username"]);
h.Password(builder.Configuration[$"{rabbitMqSection}:Password"]);
cfg.ConfigureEndpoints(context);
});
cfg.ReceiveEndpoint(thisAssembly.GetName().Name!, x =>
{
x.UseMessageRetry(r => r.Intervals(
TimeSpan.FromSeconds(1),
TimeSpan.FromSeconds(3),
TimeSpan.FromSeconds(10)));
// TODO: Add delayed redelivery - but we need a rabbitmq plugin for this
//x.UseDelayedRedelivery(r => r.Intervals(
// TimeSpan.FromMinutes(1),
// TimeSpan.FromMinutes(3),
// TimeSpan.FromMinutes(10)));
x.SetQuorumQueue();
x.ConfigureConsumers(context);
});
});
}
else
{
// todo: Configure for using Azure Service Bus
}
})
.AddApplication(builder.Configuration, builder.Environment)
.AddInfrastructure(builder.Configuration, builder.Environment)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
"Microsoft.AspNetCore": "Warning"
}
},
"RabbitMq": {
"Host": "localhost",
"Username": "guest",
"Password": "guest"
"MassTransit": {
"UseInMemoryTransport": true
},
"Infrastructure": {
"Redis": {
Expand Down
Loading