From 7d9f1f5f5ad8419ab21cae3d218db63f1b9e0ce4 Mon Sep 17 00:00:00 2001 From: Are Almaas Date: Fri, 5 Apr 2024 16:34:57 +0100 Subject: [PATCH 1/3] feat(service): use in-memory transport instead of rabbitmq --- .env | 4 --- .github/workflows/action-publish.yml | 2 -- RabbitMq/Dockerfile | 8 ----- RabbitMq/enabled_plugins | 1 - docker-compose-no-webapi.yml | 24 -------------- enabled_plugins | 1 - .../appsettings.Development.json | 7 +--- .../Digdir.Domain.Dialogporten.Service.csproj | 9 +++-- .../Program.cs | 33 +++++++------------ .../appsettings.Development.json | 6 ++-- 10 files changed, 19 insertions(+), 76 deletions(-) delete mode 100644 RabbitMq/Dockerfile delete mode 100644 RabbitMq/enabled_plugins delete mode 100644 enabled_plugins diff --git a/.env b/.env index dfb9acb1c..cbd2e3101 100644 --- a/.env +++ b/.env @@ -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 diff --git a/.github/workflows/action-publish.yml b/.github/workflows/action-publish.yml index 050603f05..8725ea3c4 100644 --- a/.github/workflows/action-publish.yml +++ b/.github/workflows/action-publish.yml @@ -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 diff --git a/RabbitMq/Dockerfile b/RabbitMq/Dockerfile deleted file mode 100644 index b7df6977c..000000000 --- a/RabbitMq/Dockerfile +++ /dev/null @@ -1,8 +0,0 @@ -FROM rabbitmq:3-management - -COPY ./RabbitMq/enabled_plugins /etc/rabbitmq/enabled_plugins - -RUN chown -R rabbitmq:rabbitmq /etc/rabbitmq/enabled_plugins - -# What ports should be exposed? -EXPOSE 4369 5671 5672 15671 15672 15692 25672 35672-35682 diff --git a/RabbitMq/enabled_plugins b/RabbitMq/enabled_plugins deleted file mode 100644 index 085db6b54..000000000 --- a/RabbitMq/enabled_plugins +++ /dev/null @@ -1 +0,0 @@ -[rabbitmq_management, rabbitmq_prometheus, rabbitmq_shovel, rabbitmq_shovel_management]. \ No newline at end of file diff --git a/docker-compose-no-webapi.yml b/docker-compose-no-webapi.yml index 1fe466a04..5883d4a89 100644 --- a/docker-compose-no-webapi.yml +++ b/docker-compose-no-webapi.yml @@ -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 @@ -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: @@ -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} diff --git a/enabled_plugins b/enabled_plugins deleted file mode 100644 index 085db6b54..000000000 --- a/enabled_plugins +++ /dev/null @@ -1 +0,0 @@ -[rabbitmq_management, rabbitmq_prometheus, rabbitmq_shovel, rabbitmq_shovel_management]. \ No newline at end of file diff --git a/src/Digdir.Domain.Dialogporten.ChangeDataCapture/appsettings.Development.json b/src/Digdir.Domain.Dialogporten.ChangeDataCapture/appsettings.Development.json index 818106014..7eb19240a 100644 --- a/src/Digdir.Domain.Dialogporten.ChangeDataCapture/appsettings.Development.json +++ b/src/Digdir.Domain.Dialogporten.ChangeDataCapture/appsettings.Development.json @@ -1,10 +1,5 @@ { "ReplicationSlotName": "outboxmessage_replication_slot", "PublicationName": "outboxmessage_publication", - "TableName": "OutboxMessage", - "RabbitMq": { - "Host": "localhost", - "Username": "guest", - "Password": "guest" - } + "TableName": "OutboxMessage" } diff --git a/src/Digdir.Domain.Dialogporten.Service/Digdir.Domain.Dialogporten.Service.csproj b/src/Digdir.Domain.Dialogporten.Service/Digdir.Domain.Dialogporten.Service.csproj index 1d51daa54..51d9c0182 100644 --- a/src/Digdir.Domain.Dialogporten.Service/Digdir.Domain.Dialogporten.Service.csproj +++ b/src/Digdir.Domain.Dialogporten.Service/Digdir.Domain.Dialogporten.Service.csproj @@ -9,16 +9,15 @@ - - + - + - - + + diff --git a/src/Digdir.Domain.Dialogporten.Service/Program.cs b/src/Digdir.Domain.Dialogporten.Service/Program.cs index bd96a720b..cee0a757e 100644 --- a/src/Digdir.Domain.Dialogporten.Service/Program.cs +++ b/src/Digdir.Domain.Dialogporten.Service/Program.cs @@ -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 @@ -60,29 +60,20 @@ static void BuildAndRun(string[] args) .AddMassTransit(x => { x.AddConsumers(thisAssembly); - x.UsingRabbitMq((context, cfg) => + + var useInMemoryTransport = builder.Configuration.GetValue("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) diff --git a/src/Digdir.Domain.Dialogporten.Service/appsettings.Development.json b/src/Digdir.Domain.Dialogporten.Service/appsettings.Development.json index 00042fc37..7544150eb 100644 --- a/src/Digdir.Domain.Dialogporten.Service/appsettings.Development.json +++ b/src/Digdir.Domain.Dialogporten.Service/appsettings.Development.json @@ -5,10 +5,8 @@ "Microsoft.AspNetCore": "Warning" } }, - "RabbitMq": { - "Host": "localhost", - "Username": "guest", - "Password": "guest" + "MassTransit": { + "UseInMemoryTransport": true }, "Infrastructure": { "Redis": { From 9cfad9cd7e31577ef9be462b506c9af45f21174d Mon Sep 17 00:00:00 2001 From: Are Almaas Date: Fri, 5 Apr 2024 16:40:46 +0100 Subject: [PATCH 2/3] feat(service): use in-memory transport instead of rabbitmq --- ...omain.Dialogporten.ChangeDataCapture.csproj | 9 ++++----- .../ICdcSink.cs | 9 --------- .../Program.cs | 18 +++++++++++------- .../appsettings.Development.json | 5 ++++- 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/Digdir.Domain.Dialogporten.ChangeDataCapture/Digdir.Domain.Dialogporten.ChangeDataCapture.csproj b/src/Digdir.Domain.Dialogporten.ChangeDataCapture/Digdir.Domain.Dialogporten.ChangeDataCapture.csproj index 435ca4e42..c17edd073 100644 --- a/src/Digdir.Domain.Dialogporten.ChangeDataCapture/Digdir.Domain.Dialogporten.ChangeDataCapture.csproj +++ b/src/Digdir.Domain.Dialogporten.ChangeDataCapture/Digdir.Domain.Dialogporten.ChangeDataCapture.csproj @@ -5,14 +5,13 @@ net8.0 enable enable - 750256a4-f332-4783-8802-8a7d9566f9ca + 750256a4-f332-4783-8802-8a7d9566f9ca - + - + - @@ -23,4 +22,4 @@ - + \ No newline at end of file diff --git a/src/Digdir.Domain.Dialogporten.ChangeDataCapture/ICdcSink.cs b/src/Digdir.Domain.Dialogporten.ChangeDataCapture/ICdcSink.cs index 18272eb25..5d065d994 100644 --- a/src/Digdir.Domain.Dialogporten.ChangeDataCapture/ICdcSink.cs +++ b/src/Digdir.Domain.Dialogporten.ChangeDataCapture/ICdcSink.cs @@ -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); } } diff --git a/src/Digdir.Domain.Dialogporten.ChangeDataCapture/Program.cs b/src/Digdir.Domain.Dialogporten.ChangeDataCapture/Program.cs index 734261833..1874fb6fe 100644 --- a/src/Digdir.Domain.Dialogporten.ChangeDataCapture/Program.cs +++ b/src/Digdir.Domain.Dialogporten.ChangeDataCapture/Program.cs @@ -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 @@ -59,15 +59,19 @@ static void BuildAndRun(string[] args) .AddHostedService() .AddMassTransit(x => { - x.UsingRabbitMq((context, cfg) => + var useInMemoryTransport = builder.Configuration.GetValue("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(x => new PostgresCdcSSubscriptionOptions ( diff --git a/src/Digdir.Domain.Dialogporten.ChangeDataCapture/appsettings.Development.json b/src/Digdir.Domain.Dialogporten.ChangeDataCapture/appsettings.Development.json index 7eb19240a..368f04c1c 100644 --- a/src/Digdir.Domain.Dialogporten.ChangeDataCapture/appsettings.Development.json +++ b/src/Digdir.Domain.Dialogporten.ChangeDataCapture/appsettings.Development.json @@ -1,5 +1,8 @@ { "ReplicationSlotName": "outboxmessage_replication_slot", "PublicationName": "outboxmessage_publication", - "TableName": "OutboxMessage" + "TableName": "OutboxMessage", + "MassTransit": { + "UseInMemoryTransport": true + } } From 2366132e5835666d0fd216db530cc6bbf8484968 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20J=C3=B8rgen=20Skogstad?= Date: Fri, 5 Apr 2024 18:30:51 +0200 Subject: [PATCH 3/3] chore: use http for webapi in docker compose (#603) --- docker-compose.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/docker-compose.yml b/docker-compose.yml index 2e304d8d4..f67750305 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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