From c6a1ce820a827357ff868e7b992281b61c583617 Mon Sep 17 00:00:00 2001 From: Hans Dahle Date: Tue, 17 Oct 2023 09:15:47 +0200 Subject: [PATCH 1/7] Removed deprecated azure key vault nuget package --- .../api/Fusion.Resources.Api/Fusion.Resources.Api.csproj | 2 +- src/backend/api/Fusion.Resources.Api/Program.cs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/backend/api/Fusion.Resources.Api/Fusion.Resources.Api.csproj b/src/backend/api/Fusion.Resources.Api/Fusion.Resources.Api.csproj index 0fe72fd8d..798cedc34 100644 --- a/src/backend/api/Fusion.Resources.Api/Fusion.Resources.Api.csproj +++ b/src/backend/api/Fusion.Resources.Api/Fusion.Resources.Api.csproj @@ -15,6 +15,7 @@ + @@ -30,7 +31,6 @@ - diff --git a/src/backend/api/Fusion.Resources.Api/Program.cs b/src/backend/api/Fusion.Resources.Api/Program.cs index f1a883b86..7dfa581cd 100644 --- a/src/backend/api/Fusion.Resources.Api/Program.cs +++ b/src/backend/api/Fusion.Resources.Api/Program.cs @@ -1,4 +1,5 @@ using System; +using Azure.Identity; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; @@ -38,6 +39,7 @@ private static void AddKeyVault(HostBuilderContext hostBuilderContext, IConfigur { var tempConfig = configBuilder.Build(); var clientId = tempConfig["AzureAd:ClientId"]; + var tenantId = tempConfig["AzureAd:TenantId"]; var clientSecret = tempConfig["AzureAd:ClientSecret"]; var keyVaultUrl = tempConfig["KEYVAULT_URL"]; @@ -45,7 +47,8 @@ private static void AddKeyVault(HostBuilderContext hostBuilderContext, IConfigur { Console.WriteLine($"Adding key vault using url: '{keyVaultUrl}', client id '{clientId}' and client secret {(string.IsNullOrEmpty(clientSecret) ? "[empty]" : "*****")}"); - configBuilder.AddAzureKeyVault(keyVaultUrl, clientId, clientSecret); + var credential = new ClientSecretCredential(tenantId, clientId, clientSecret); + configBuilder.AddAzureKeyVault(new Uri(keyVaultUrl), credential); } else { From 2fe3e3916c74c6895defd1762f45ac4653ae5211 Mon Sep 17 00:00:00 2001 From: Hans Dahle Date: Tue, 17 Oct 2023 12:01:57 +0200 Subject: [PATCH 2/7] Updated to net7.0 --- src/backend/.config/dotnet-tools.json | 2 +- .../Fusion.Resources.Authorization.csproj | 2 +- .../Fusion.Resources.Api.csproj | 8 ++-- .../Fusion.Resources.Application.csproj | 10 ++--- .../ServiceBus/ServiceBusService.cs | 41 ++++++++++++------- .../Fusion.Resources.Database.csproj | 12 +++--- .../Fusion.Resources.Domain.csproj | 2 +- .../Fusion.Resources.Logic.csproj | 2 +- .../Fusion.Resources.Api.Tests.csproj | 16 ++++---- .../EventNotificationClientMock.cs | 8 ++-- .../FusionMocks/TestMessageBus.cs | 20 ++++----- .../FusionMocks/TestQueueMessage.cs | 4 +- .../Fusion.Resources.Domain.Tests.csproj | 17 ++++---- .../Fusion.Resources.Functions.Tests.csproj | 12 +++--- .../Fusion.Resources.Logic.Tests.csproj | 12 +++--- .../Fusion.Resources.Test.Core.csproj | 7 ++-- .../Fusion.Testing.Authentication.csproj | 4 +- .../Fusion.Testing.Core.csproj | 6 +-- ...Fusion.Testing.Mocks.ContextService.csproj | 6 +-- ...Fusion.Testing.Mocks.LineOrgService.csproj | 4 +- .../Fusion.Testing.Mocks.OrgService.csproj | 4 +- ...Fusion.Testing.Mocks.ProfileService.csproj | 4 +- 22 files changed, 105 insertions(+), 98 deletions(-) diff --git a/src/backend/.config/dotnet-tools.json b/src/backend/.config/dotnet-tools.json index 4ab94945c..2f789b031 100644 --- a/src/backend/.config/dotnet-tools.json +++ b/src/backend/.config/dotnet-tools.json @@ -3,7 +3,7 @@ "isRoot": true, "tools": { "dotnet-ef": { - "version": "5.0.2", + "version": "7.0.12", "commands": [ "dotnet-ef" ] diff --git a/src/backend/Fusion.Resources.Authorization/Fusion.Resources.Authorization.csproj b/src/backend/Fusion.Resources.Authorization/Fusion.Resources.Authorization.csproj index 3d1ea1b90..ce40b4324 100644 --- a/src/backend/Fusion.Resources.Authorization/Fusion.Resources.Authorization.csproj +++ b/src/backend/Fusion.Resources.Authorization/Fusion.Resources.Authorization.csproj @@ -1,7 +1,7 @@ - net6.0 + net7.0 enable diff --git a/src/backend/api/Fusion.Resources.Api/Fusion.Resources.Api.csproj b/src/backend/api/Fusion.Resources.Api/Fusion.Resources.Api.csproj index 798cedc34..70606aff0 100644 --- a/src/backend/api/Fusion.Resources.Api/Fusion.Resources.Api.csproj +++ b/src/backend/api/Fusion.Resources.Api/Fusion.Resources.Api.csproj @@ -1,6 +1,6 @@  - net6.0 + net7.0 474454c7-2021-4f46-bfd4-02b221fc3fa0 Linux ..\.. @@ -30,14 +30,14 @@ - + - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/backend/api/Fusion.Resources.Application/Fusion.Resources.Application.csproj b/src/backend/api/Fusion.Resources.Application/Fusion.Resources.Application.csproj index 549f0db3c..1413ad79d 100644 --- a/src/backend/api/Fusion.Resources.Application/Fusion.Resources.Application.csproj +++ b/src/backend/api/Fusion.Resources.Application/Fusion.Resources.Application.csproj @@ -1,16 +1,16 @@  - net6.0 + net7.0 enable + - - - - + + + diff --git a/src/backend/api/Fusion.Resources.Application/ServiceBus/ServiceBusService.cs b/src/backend/api/Fusion.Resources.Application/ServiceBus/ServiceBusService.cs index 1d21db1f2..d4f7d8cf1 100644 --- a/src/backend/api/Fusion.Resources.Application/ServiceBus/ServiceBusService.cs +++ b/src/backend/api/Fusion.Resources.Application/ServiceBus/ServiceBusService.cs @@ -1,22 +1,28 @@ using System; -using Microsoft.Azure.ServiceBus.Core; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; -using System.Text; using System.Text.Json; using System.Threading.Tasks; +using Azure.Messaging.ServiceBus; namespace Fusion.Resources.ServiceBus { internal class ServiceBusQueueSender : IQueueSender { - private readonly string connectionString; private readonly IConfiguration configuration; private readonly ILogger logger; + private ServiceBusClient? client; public ServiceBusQueueSender(IConfiguration configuration, ILogger logger) { - connectionString = configuration.GetConnectionString("ServiceBus"); + var connectionString = configuration.GetConnectionString("ServiceBus"); + + // Leaving this as nullable so integration tests etc don't fail untill the functionality is required. + if (!string.IsNullOrEmpty(connectionString)) + { + this.client = new ServiceBusClient(connectionString); + } + this.configuration = configuration; this.logger = logger; } @@ -30,17 +36,25 @@ public async Task SendMessageDelayedAsync(QueuePath queue, object message, int d { if (!IsDisabled) { - var sender = GetClient(queue); + if (client is null) + throw new InvalidOperationException("Service bus has not been configured. Missing connection string."); + var jsonMessage = JsonSerializer.Serialize(message); - var queueMessage = new Microsoft.Azure.ServiceBus.Message(Encoding.UTF8.GetBytes(jsonMessage)) { ContentType = "application/json" }; + var entityPath = Resolve(queue); + + if (string.IsNullOrEmpty(entityPath)) + throw new InvalidOperationException($"Could not resolve the serivce bus entity path for queue '{queue}'"); + + var queueSender = client.CreateSender(entityPath); + + + var sbMessage = new ServiceBusMessage(jsonMessage) { ContentType = "application/json" }; if (delayInSeconds > 0) - { - queueMessage.ScheduledEnqueueTimeUtc = DateTime.UtcNow.AddSeconds(delayInSeconds); - } + sbMessage.ScheduledEnqueueTime = DateTime.UtcNow.AddSeconds(delayInSeconds); - logger.LogInformation($"Posting message to {sender.Path}: {jsonMessage}"); - await sender.SendAsync(queueMessage); + logger.LogInformation($"Posting message to {entityPath}: {jsonMessage}"); + await queueSender.SendMessageAsync(sbMessage); } else { @@ -48,7 +62,7 @@ public async Task SendMessageDelayedAsync(QueuePath queue, object message, int d } } - private MessageSender GetClient(QueuePath queue) + private string? Resolve(QueuePath queue) { var entityPath = configuration.GetValue($"ServiceBus:Queues:{queue}", DefaultQueuePath(queue)); @@ -58,8 +72,7 @@ private MessageSender GetClient(QueuePath queue) logger.LogInformation($"Using service bus queue: {entityPath}"); - var sender = new MessageSender(connectionString, entityPath); - return sender; + return entityPath; } private bool IsDisabled => configuration.GetValue("ServiceBus:Disabled", false); diff --git a/src/backend/api/Fusion.Resources.Database/Fusion.Resources.Database.csproj b/src/backend/api/Fusion.Resources.Database/Fusion.Resources.Database.csproj index 3853f6e15..4e37d056d 100644 --- a/src/backend/api/Fusion.Resources.Database/Fusion.Resources.Database.csproj +++ b/src/backend/api/Fusion.Resources.Database/Fusion.Resources.Database.csproj @@ -1,20 +1,20 @@  - net6.0 + net7.0 enable - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + diff --git a/src/backend/api/Fusion.Resources.Domain/Fusion.Resources.Domain.csproj b/src/backend/api/Fusion.Resources.Domain/Fusion.Resources.Domain.csproj index 5874357c3..fb438f836 100644 --- a/src/backend/api/Fusion.Resources.Domain/Fusion.Resources.Domain.csproj +++ b/src/backend/api/Fusion.Resources.Domain/Fusion.Resources.Domain.csproj @@ -1,7 +1,7 @@  - net6.0 + net7.0 enable diff --git a/src/backend/api/Fusion.Resources.Logic/Fusion.Resources.Logic.csproj b/src/backend/api/Fusion.Resources.Logic/Fusion.Resources.Logic.csproj index 41fc1e53a..045d6375f 100644 --- a/src/backend/api/Fusion.Resources.Logic/Fusion.Resources.Logic.csproj +++ b/src/backend/api/Fusion.Resources.Logic/Fusion.Resources.Logic.csproj @@ -1,7 +1,7 @@ - net6.0 + net7.0 enable diff --git a/src/backend/tests/Fusion.Resources.Api.Tests/Fusion.Resources.Api.Tests.csproj b/src/backend/tests/Fusion.Resources.Api.Tests/Fusion.Resources.Api.Tests.csproj index 2b732a962..0d3d18739 100644 --- a/src/backend/tests/Fusion.Resources.Api.Tests/Fusion.Resources.Api.Tests.csproj +++ b/src/backend/tests/Fusion.Resources.Api.Tests/Fusion.Resources.Api.Tests.csproj @@ -1,7 +1,7 @@ - net6.0 + net7.0 false @@ -17,16 +17,14 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -34,7 +32,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/src/backend/tests/Fusion.Resources.Api.Tests/FusionMocks/EventNotificationClientMock.cs b/src/backend/tests/Fusion.Resources.Api.Tests/FusionMocks/EventNotificationClientMock.cs index 64dd57e4d..e67a9df81 100644 --- a/src/backend/tests/Fusion.Resources.Api.Tests/FusionMocks/EventNotificationClientMock.cs +++ b/src/backend/tests/Fusion.Resources.Api.Tests/FusionMocks/EventNotificationClientMock.cs @@ -1,6 +1,6 @@ +using Azure.Messaging.ServiceBus; using Bogus; using Fusion.Events; -using Microsoft.Azure.ServiceBus; using Newtonsoft.Json; using System; using System.Collections.Generic; @@ -82,16 +82,16 @@ private Task DispatchNotification(FusionEventType type, FusionEventCategory c var messageBody = JsonConvert.SerializeObject(cEvent); - var sbMessage = new Message(Encoding.UTF8.GetBytes(messageBody)) + var sbMessage = new ServiceBusMessage(Encoding.UTF8.GetBytes(messageBody)) { MessageId = $"{type.Name}-{cEvent.Id}" }; - sbMessage.UserProperties.Add("type", type.Name); + sbMessage.ApplicationProperties.Add("type", type.Name); if (!string.IsNullOrEmpty(appContext)) { - sbMessage.UserProperties.Add("app", appContext); + sbMessage.ApplicationProperties.Add("app", appContext); } return bus.PublishMessageAsync(entityPath, sbMessage); diff --git a/src/backend/tests/Fusion.Resources.Api.Tests/FusionMocks/TestMessageBus.cs b/src/backend/tests/Fusion.Resources.Api.Tests/FusionMocks/TestMessageBus.cs index af4bfa289..bc05376c3 100644 --- a/src/backend/tests/Fusion.Resources.Api.Tests/FusionMocks/TestMessageBus.cs +++ b/src/backend/tests/Fusion.Resources.Api.Tests/FusionMocks/TestMessageBus.cs @@ -1,4 +1,4 @@ -using Microsoft.Azure.ServiceBus; +using Azure.Messaging.ServiceBus; using Newtonsoft.Json; using System; using System.Collections.Generic; @@ -18,11 +18,11 @@ public class TestMessageBus private static List localMessages = new List(); private static List queueExecutionTasks = new List(); - private static Dictionary>> queueHandlers = new Dictionary>>(); + private static Dictionary>> queueHandlers = new Dictionary>>(); private static object writeLock = new object(); - public Task PublishMessageAsync(string entityPath, Message message) + public Task PublishMessageAsync(string entityPath, ServiceBusMessage message) { if (IsTemporarilyUnavailable) { @@ -53,22 +53,22 @@ public Task PublishMessageAsync(string entityPath, Message message) } - public void RegisterQueueHandler(string queuepath, Func callback) + public void RegisterQueueHandler(string queuepath, Func callback) { lock (writeLock) { - queueHandlers[queuepath] = new List>() { callback }; + queueHandlers[queuepath] = new List>() { callback }; } } - public void RegisterTopicHandler(string queuepath, Func callback) + public void RegisterTopicHandler(string queuepath, Func callback) { lock (writeLock) { if (queueHandlers.ContainsKey(queuepath)) queueHandlers[queuepath].Add(callback); else - queueHandlers[queuepath] = new List>() { callback }; + queueHandlers[queuepath] = new List>() { callback }; } } @@ -77,7 +77,7 @@ public void RegisterTopicHandler(string queuepath, Func callback) public static IReadOnlyCollection GetAllMessages() => allMessages.AsReadOnly(); public static List GetAllMessagePayloadsForPerson(Func predicate, string aadPersonId, T payloadType) { - var filtered = allMessages.Where(predicate).OrderBy(m => m.Message.ScheduledEnqueueTimeUtc); + var filtered = allMessages.Where(predicate).OrderBy(m => m.Message.ScheduledEnqueueTime); var result = new List(); foreach (var msg in filtered) @@ -104,7 +104,7 @@ public static List GetAllMessagePayloadsForPerson(Func GetAllMessages() { - var filtered = allMessages.OrderBy(m => m.Message.ScheduledEnqueueTimeUtc); + var filtered = allMessages.OrderBy(m => m.Message.ScheduledEnqueueTime); var result = new List(); foreach (var msg in filtered) @@ -138,7 +138,7 @@ public static Task FinishProcessingAsync() public List GetLocalMessages() { - var filtered = localMessages.OrderBy(m => m.Message.ScheduledEnqueueTimeUtc); + var filtered = localMessages.OrderBy(m => m.Message.ScheduledEnqueueTime); var result = new List(); foreach (var msg in filtered) diff --git a/src/backend/tests/Fusion.Resources.Api.Tests/FusionMocks/TestQueueMessage.cs b/src/backend/tests/Fusion.Resources.Api.Tests/FusionMocks/TestQueueMessage.cs index 7457b23d2..d24a63f71 100644 --- a/src/backend/tests/Fusion.Resources.Api.Tests/FusionMocks/TestQueueMessage.cs +++ b/src/backend/tests/Fusion.Resources.Api.Tests/FusionMocks/TestQueueMessage.cs @@ -1,11 +1,11 @@ -using Microsoft.Azure.ServiceBus; +using Azure.Messaging.ServiceBus; namespace Fusion.Resources.Api.Tests.FusionMocks { public class TestQueueMessage { public string Path { get; set; } - public Message Message { get; set; } + public ServiceBusMessage Message { get; set; } public bool Processed { get; set; } public string BodyText { get; set; } } diff --git a/src/backend/tests/Fusion.Resources.Domain.Tests/Fusion.Resources.Domain.Tests.csproj b/src/backend/tests/Fusion.Resources.Domain.Tests/Fusion.Resources.Domain.Tests.csproj index dfa80949c..ce00a9a7c 100644 --- a/src/backend/tests/Fusion.Resources.Domain.Tests/Fusion.Resources.Domain.Tests.csproj +++ b/src/backend/tests/Fusion.Resources.Domain.Tests/Fusion.Resources.Domain.Tests.csproj @@ -1,7 +1,7 @@ - + - net6.0 + net7.0 false @@ -9,18 +9,15 @@ - - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - + + - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/backend/tests/Fusion.Resources.Functions.Tests/Fusion.Resources.Functions.Tests.csproj b/src/backend/tests/Fusion.Resources.Functions.Tests/Fusion.Resources.Functions.Tests.csproj index 3df5d44d8..79d231c49 100644 --- a/src/backend/tests/Fusion.Resources.Functions.Tests/Fusion.Resources.Functions.Tests.csproj +++ b/src/backend/tests/Fusion.Resources.Functions.Tests/Fusion.Resources.Functions.Tests.csproj @@ -1,20 +1,20 @@ - net6.0 + net7.0 false - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/backend/tests/Fusion.Resources.Logic.Tests/Fusion.Resources.Logic.Tests.csproj b/src/backend/tests/Fusion.Resources.Logic.Tests/Fusion.Resources.Logic.Tests.csproj index 98a79dc2b..838131c1e 100644 --- a/src/backend/tests/Fusion.Resources.Logic.Tests/Fusion.Resources.Logic.Tests.csproj +++ b/src/backend/tests/Fusion.Resources.Logic.Tests/Fusion.Resources.Logic.Tests.csproj @@ -1,21 +1,19 @@ - net6.0 + net7.0 false - - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/backend/tests/Fusion.Resources.Test.Core/Fusion.Resources.Test.Core.csproj b/src/backend/tests/Fusion.Resources.Test.Core/Fusion.Resources.Test.Core.csproj index 34898f8fe..ffe6f059b 100644 --- a/src/backend/tests/Fusion.Resources.Test.Core/Fusion.Resources.Test.Core.csproj +++ b/src/backend/tests/Fusion.Resources.Test.Core/Fusion.Resources.Test.Core.csproj @@ -1,12 +1,13 @@ - + - net6.0 + net7.0 + - + diff --git a/src/backend/tests/Fusion.Testing.Authentication/Fusion.Testing.Authentication.csproj b/src/backend/tests/Fusion.Testing.Authentication/Fusion.Testing.Authentication.csproj index 8b5afd679..ca3ff3a4a 100644 --- a/src/backend/tests/Fusion.Testing.Authentication/Fusion.Testing.Authentication.csproj +++ b/src/backend/tests/Fusion.Testing.Authentication/Fusion.Testing.Authentication.csproj @@ -1,7 +1,7 @@ - net6.0 + net7.0 @@ -9,7 +9,7 @@ - + diff --git a/src/backend/tests/Fusion.Testing.Core/Fusion.Testing.Core.csproj b/src/backend/tests/Fusion.Testing.Core/Fusion.Testing.Core.csproj index 757c53a83..f530e4eea 100644 --- a/src/backend/tests/Fusion.Testing.Core/Fusion.Testing.Core.csproj +++ b/src/backend/tests/Fusion.Testing.Core/Fusion.Testing.Core.csproj @@ -1,13 +1,13 @@ - net6.0 + net7.0 - - + + diff --git a/src/backend/tests/Fusion.Testing.Mocks.ContextService/Fusion.Testing.Mocks.ContextService.csproj b/src/backend/tests/Fusion.Testing.Mocks.ContextService/Fusion.Testing.Mocks.ContextService.csproj index 00ae56285..48b12370c 100644 --- a/src/backend/tests/Fusion.Testing.Mocks.ContextService/Fusion.Testing.Mocks.ContextService.csproj +++ b/src/backend/tests/Fusion.Testing.Mocks.ContextService/Fusion.Testing.Mocks.ContextService.csproj @@ -1,13 +1,13 @@ - net6.0 + net7.0 - - + + diff --git a/src/backend/tests/Fusion.Testing.Mocks.LineOrgService/Fusion.Testing.Mocks.LineOrgService.csproj b/src/backend/tests/Fusion.Testing.Mocks.LineOrgService/Fusion.Testing.Mocks.LineOrgService.csproj index cd2437a53..321b89581 100644 --- a/src/backend/tests/Fusion.Testing.Mocks.LineOrgService/Fusion.Testing.Mocks.LineOrgService.csproj +++ b/src/backend/tests/Fusion.Testing.Mocks.LineOrgService/Fusion.Testing.Mocks.LineOrgService.csproj @@ -1,13 +1,13 @@ - net6.0 + net7.0 - + diff --git a/src/backend/tests/Fusion.Testing.Mocks.OrgService/Fusion.Testing.Mocks.OrgService.csproj b/src/backend/tests/Fusion.Testing.Mocks.OrgService/Fusion.Testing.Mocks.OrgService.csproj index 7075a7d15..2315063d9 100644 --- a/src/backend/tests/Fusion.Testing.Mocks.OrgService/Fusion.Testing.Mocks.OrgService.csproj +++ b/src/backend/tests/Fusion.Testing.Mocks.OrgService/Fusion.Testing.Mocks.OrgService.csproj @@ -1,7 +1,7 @@ - net6.0 + net7.0 @@ -16,7 +16,7 @@ - + diff --git a/src/backend/tests/Fusion.Testing.Mocks.ProfileService/Fusion.Testing.Mocks.ProfileService.csproj b/src/backend/tests/Fusion.Testing.Mocks.ProfileService/Fusion.Testing.Mocks.ProfileService.csproj index 1899de46e..4d62812a8 100644 --- a/src/backend/tests/Fusion.Testing.Mocks.ProfileService/Fusion.Testing.Mocks.ProfileService.csproj +++ b/src/backend/tests/Fusion.Testing.Mocks.ProfileService/Fusion.Testing.Mocks.ProfileService.csproj @@ -1,7 +1,7 @@ - net6.0 + net7.0 @@ -9,7 +9,7 @@ - + From 5af5067a315fb0bcd176438472424d06b31d86a8 Mon Sep 17 00:00:00 2001 From: Hans Dahle Date: Tue, 17 Oct 2023 12:25:04 +0200 Subject: [PATCH 3/7] Updated dockerfile to net7 --- src/backend/api/Fusion.Resources.Api/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/api/Fusion.Resources.Api/Dockerfile b/src/backend/api/Fusion.Resources.Api/Dockerfile index e04b7a904..547974c48 100644 --- a/src/backend/api/Fusion.Resources.Api/Dockerfile +++ b/src/backend/api/Fusion.Resources.Api/Dockerfile @@ -1,11 +1,11 @@ #See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. -FROM mcr.microsoft.com/dotnet/aspnet:6.0-bullseye-slim AS base +FROM mcr.microsoft.com/dotnet/aspnet:7.0-bullseye-slim AS base WORKDIR /app EXPOSE 80 EXPOSE 443 -FROM mcr.microsoft.com/dotnet/sdk:6.0-bullseye-slim AS build +FROM mcr.microsoft.com/dotnet/sdk:7.0-bullseye-slim AS build WORKDIR /src COPY ["api/Fusion.Resources.Api/Fusion.Resources.Api.csproj", "api/Fusion.Resources.Api/"] COPY ["api/Fusion.Resources.Database/Fusion.Resources.Database.csproj", "api/Fusion.Resources.Database/"] From e55eb7d85a55e3a9ca4f4987207dff2a026d5e56 Mon Sep 17 00:00:00 2001 From: Hans Dahle Date: Tue, 17 Oct 2023 12:27:11 +0200 Subject: [PATCH 4/7] Updated gha to net7 --- .github/workflows/test-api.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-api.yml b/.github/workflows/test-api.yml index 64580c491..b5406625a 100644 --- a/.github/workflows/test-api.yml +++ b/.github/workflows/test-api.yml @@ -38,7 +38,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v1 with: - dotnet-version: 6.0.x + dotnet-version: 7.0.x - name: Restore dependencies run: dotnet restore - name: Build From 54bccd49c73290c33331790a0f6925ddafedc316 Mon Sep 17 00:00:00 2001 From: Hans Dahle Date: Tue, 17 Oct 2023 15:37:32 +0200 Subject: [PATCH 5/7] Refactored bad naming of method --- .../ServiceBus/ServiceBusService.cs | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/backend/api/Fusion.Resources.Application/ServiceBus/ServiceBusService.cs b/src/backend/api/Fusion.Resources.Application/ServiceBus/ServiceBusService.cs index d4f7d8cf1..6087beaa4 100644 --- a/src/backend/api/Fusion.Resources.Application/ServiceBus/ServiceBusService.cs +++ b/src/backend/api/Fusion.Resources.Application/ServiceBus/ServiceBusService.cs @@ -41,13 +41,8 @@ public async Task SendMessageDelayedAsync(QueuePath queue, object message, int d var jsonMessage = JsonSerializer.Serialize(message); - var entityPath = Resolve(queue); - - if (string.IsNullOrEmpty(entityPath)) - throw new InvalidOperationException($"Could not resolve the serivce bus entity path for queue '{queue}'"); - + var entityPath = ResolveQueuePath(queue); var queueSender = client.CreateSender(entityPath); - var sbMessage = new ServiceBusMessage(jsonMessage) { ContentType = "application/json" }; if (delayInSeconds > 0) @@ -62,14 +57,24 @@ public async Task SendMessageDelayedAsync(QueuePath queue, object message, int d } } - private string? Resolve(QueuePath queue) + /// + /// Queue path should be configured in config. The config key should be the enum value. + /// + /// + /// + /// + private string ResolveQueuePath(QueuePath queue) { - var entityPath = configuration.GetValue($"ServiceBus:Queues:{queue}", DefaultQueuePath(queue)); + var entityPath = configuration.GetValue($"ServiceBus:Queues:{queue}"); + var entityPathOverride = configuration.GetValue($"SERVICEBUS_QUEUES_{queue}"); if (!string.IsNullOrEmpty(entityPathOverride)) entityPath = entityPathOverride; + if (string.IsNullOrEmpty(entityPath)) + entityPath = DefaultQueuePath(queue); + logger.LogInformation($"Using service bus queue: {entityPath}"); return entityPath; From effc2ae5b6f5bedde97b8bd064fc6e7ea5fb8d71 Mon Sep 17 00:00:00 2001 From: Hans Dahle Date: Tue, 17 Oct 2023 16:04:08 +0200 Subject: [PATCH 6/7] Added caching of service bus sender. --- .../ServiceBus/ServiceBusService.cs | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/backend/api/Fusion.Resources.Application/ServiceBus/ServiceBusService.cs b/src/backend/api/Fusion.Resources.Application/ServiceBus/ServiceBusService.cs index 6087beaa4..aee22f603 100644 --- a/src/backend/api/Fusion.Resources.Application/ServiceBus/ServiceBusService.cs +++ b/src/backend/api/Fusion.Resources.Application/ServiceBus/ServiceBusService.cs @@ -4,6 +4,7 @@ using System.Text.Json; using System.Threading.Tasks; using Azure.Messaging.ServiceBus; +using System.Collections.Generic; namespace Fusion.Resources.ServiceBus { @@ -11,7 +12,10 @@ internal class ServiceBusQueueSender : IQueueSender { private readonly IConfiguration configuration; private readonly ILogger logger; - private ServiceBusClient? client; + private readonly ServiceBusClient? client; + + // Caching the sender is recommended when the application is publishing messages regularly or semi-regularly. The sender is responsible for ensuring efficient network, CPU, and memory use + private Dictionary cachedSenders = new Dictionary(); public ServiceBusQueueSender(IConfiguration configuration, ILogger logger) { @@ -36,13 +40,10 @@ public async Task SendMessageDelayedAsync(QueuePath queue, object message, int d { if (!IsDisabled) { - if (client is null) - throw new InvalidOperationException("Service bus has not been configured. Missing connection string."); - var jsonMessage = JsonSerializer.Serialize(message); var entityPath = ResolveQueuePath(queue); - var queueSender = client.CreateSender(entityPath); + var queueSender = GetQueueSender(entityPath); var sbMessage = new ServiceBusMessage(jsonMessage) { ContentType = "application/json" }; if (delayInSeconds > 0) @@ -57,6 +58,20 @@ public async Task SendMessageDelayedAsync(QueuePath queue, object message, int d } } + private ServiceBusSender GetQueueSender(string queue) + { + if (client is null) + throw new InvalidOperationException("Service bus has not been configured. Missing connection string."); + + if (cachedSenders.ContainsKey(queue)) + { + return cachedSenders[queue]; + } + + cachedSenders[queue] = client.CreateSender(queue); + return cachedSenders[queue]; + } + /// /// Queue path should be configured in config. The config key should be the enum value. /// From 34839b7aea4afc8cced870b2e64fba0a602aa428 Mon Sep 17 00:00:00 2001 From: Hans Dahle Date: Tue, 17 Oct 2023 16:35:05 +0200 Subject: [PATCH 7/7] Fixed test error where collection is modified when logging debug --- .../IntegrationTests/InternalRequests/DirectRequestTests.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/backend/tests/Fusion.Resources.Api.Tests/IntegrationTests/InternalRequests/DirectRequestTests.cs b/src/backend/tests/Fusion.Resources.Api.Tests/IntegrationTests/InternalRequests/DirectRequestTests.cs index f7bd77aee..167bc77b6 100644 --- a/src/backend/tests/Fusion.Resources.Api.Tests/IntegrationTests/InternalRequests/DirectRequestTests.cs +++ b/src/backend/tests/Fusion.Resources.Api.Tests/IntegrationTests/InternalRequests/DirectRequestTests.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Collections.Immutable; using System.Linq; using System.Net.Http; using System.Threading.Tasks; @@ -609,7 +610,7 @@ public async Task DirectRequest_AutoApproval_ShouldNotSendNotification_WhenAutoA #region assert TestLogger.TryLog($"{JsonConvert.SerializeObject(new { testRequest })}"); - TestLogger.TryLog($"{JsonConvert.SerializeObject(NotificationClientMock.SentMessages)}"); + TestLogger.TryLog($"{JsonConvert.SerializeObject(NotificationClientMock.SentMessages.ToImmutableList())}"); var notificationsForRequest = NotificationClientMock.SentMessages.GetNotificationsForRequestId(testRequest.Id); notificationsForRequest.Should()