From a0ade4a984327fcd842fca5c3d1764870de2ee18 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Thu, 1 Jul 2021 12:18:41 +0200 Subject: [PATCH] Fix rebus message type queue mixup --- src/core/Elsa.Core/ElsaOptions.cs | 12 ++++++++---- .../Dispatch/QueuingWorkflowDispatcher.cs | 2 +- .../Services/Messaging/ServiceBusFactory.cs | 14 +++++++------- .../elsa-workflows-studio/package-lock.json | 2 +- ...ashboard.Samples.AspNetCore.Monolith.csproj | 18 +++++++++--------- 5 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/core/Elsa.Core/ElsaOptions.cs b/src/core/Elsa.Core/ElsaOptions.cs index 82c69762c..e0bd103ac 100644 --- a/src/core/Elsa.Core/ElsaOptions.cs +++ b/src/core/Elsa.Core/ElsaOptions.cs @@ -15,6 +15,7 @@ using Microsoft.Extensions.DependencyInjection; using Newtonsoft.Json; using NodaTime; using Rebus.Persistence.InMem; +using Rebus.Routing.TypeBased; using Rebus.Transport.InMem; using Storage.Net; using Storage.Net.Blobs; @@ -25,12 +26,15 @@ namespace Elsa public class ElsaOptions { - public static string FormatChannelQueueName(string? channel = default) + public static string FormatChannelQueueName(string channel) => FormatChannelQueueName(typeof(TMessage), channel); + + public static string FormatChannelQueueName(Type messageType, string channel) { - var queue = !string.IsNullOrWhiteSpace(channel) ? $"{typeof(TMessage).Name}{channel}" : typeof(TMessage).Name; - - return queue.Dehumanize().Underscore().Dasherize(); + var queue = !string.IsNullOrWhiteSpace(channel) ? $"{messageType.Name}{channel}" : messageType.Name; + return FormatQueueName(queue); } + + public static string FormatQueueName(string queue) => queue.Dehumanize().Underscore().Dasherize(); internal ElsaOptions() { diff --git a/src/core/Elsa.Core/Services/Dispatch/QueuingWorkflowDispatcher.cs b/src/core/Elsa.Core/Services/Dispatch/QueuingWorkflowDispatcher.cs index a71aa8b30..d64068b25 100644 --- a/src/core/Elsa.Core/Services/Dispatch/QueuingWorkflowDispatcher.cs +++ b/src/core/Elsa.Core/Services/Dispatch/QueuingWorkflowDispatcher.cs @@ -66,7 +66,7 @@ namespace Elsa.Services.Dispatch } var channel = _workflowChannelOptions.GetChannelOrDefault(workflowBlueprint.Channel); - var queue = ElsaOptions.FormatChannelQueueName(channel); + var queue = ElsaOptions.FormatChannelQueueName(channel); await _commandSender.SendAsync(request, queue, default, cancellationToken); } } diff --git a/src/core/Elsa.Core/Services/Messaging/ServiceBusFactory.cs b/src/core/Elsa.Core/Services/Messaging/ServiceBusFactory.cs index c066aac51..bd9aa9093 100644 --- a/src/core/Elsa.Core/Services/Messaging/ServiceBusFactory.cs +++ b/src/core/Elsa.Core/Services/Messaging/ServiceBusFactory.cs @@ -33,19 +33,19 @@ namespace Elsa.Services.Messaging public async Task GetServiceBusAsync(Type messageType, string? queueName = default, CancellationToken cancellationToken = default) { if (string.IsNullOrWhiteSpace(queueName)) - queueName = messageType.Name; + queueName = ElsaOptions.FormatChannelQueueName(messageType, _elsaOptions.WorkflowChannelOptions.Default); - var formattedQueueName = FormatQueueName(queueName); + var prefixedQueueName = PrefixQueueName(queueName); await _semaphore.WaitAsync(cancellationToken); try { - if (_serviceBuses.TryGetValue(formattedQueueName, out var bus)) + if (_serviceBuses.TryGetValue(prefixedQueueName, out var bus)) return bus; var configurer = Configure.With(_handlerActivator); - var map = new Dictionary { [messageType] = formattedQueueName }; - var configureContext = new ServiceBusEndpointConfigurationContext(configurer, formattedQueueName, map, _serviceProvider); + var map = new Dictionary { [messageType] = prefixedQueueName }; + var configureContext = new ServiceBusEndpointConfigurationContext(configurer, prefixedQueueName, map, _serviceProvider); // Default options. configurer @@ -58,7 +58,7 @@ namespace Elsa.Services.Messaging _elsaOptions.ConfigureServiceBusEndpoint(configureContext); var newBus = configurer.Start(); - _serviceBuses.TryAdd(formattedQueueName, newBus); + _serviceBuses.TryAdd(prefixedQueueName, newBus); return newBus; } @@ -68,6 +68,6 @@ namespace Elsa.Services.Messaging } } - private string FormatQueueName(string name) => $"{_elsaOptions.ServiceBusOptions.QueuePrefix}{name}"; + private string PrefixQueueName(string name) => $"{_elsaOptions.ServiceBusOptions.QueuePrefix}{name}"; } } \ No newline at end of file diff --git a/src/designer/elsa-workflows-studio/package-lock.json b/src/designer/elsa-workflows-studio/package-lock.json index 3fb74c44e..1ae4c240e 100644 --- a/src/designer/elsa-workflows-studio/package-lock.json +++ b/src/designer/elsa-workflows-studio/package-lock.json @@ -1,6 +1,6 @@ { "name": "@elsa-workflows/elsa-workflows-studio", - "version": "2.1.0", + "version": "2.1.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/samples/dashboard/aspnetcore/ElsaDashboard.Samples.AspNetCore.Monolith/ElsaDashboard.Samples.AspNetCore.Monolith.csproj b/src/samples/dashboard/aspnetcore/ElsaDashboard.Samples.AspNetCore.Monolith/ElsaDashboard.Samples.AspNetCore.Monolith.csproj index 8b7f6e662..6f88a8f87 100644 --- a/src/samples/dashboard/aspnetcore/ElsaDashboard.Samples.AspNetCore.Monolith/ElsaDashboard.Samples.AspNetCore.Monolith.csproj +++ b/src/samples/dashboard/aspnetcore/ElsaDashboard.Samples.AspNetCore.Monolith/ElsaDashboard.Samples.AspNetCore.Monolith.csproj @@ -6,18 +6,18 @@ - + - - - - - - - - + + + + + + + +