From 54bccd49c73290c33331790a0f6925ddafedc316 Mon Sep 17 00:00:00 2001 From: Hans Dahle Date: Tue, 17 Oct 2023 15:37:32 +0200 Subject: [PATCH] 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;