From cca79a13b4ea86ec6da048e59353e204654a0c63 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Wed, 27 Aug 2025 17:38:26 +0800 Subject: [PATCH 1/2] Start Rebus after RebusDistributedEventBus is initialized --- .../Abp/EventBus/Rebus/AbpEventBusRebusModule.cs | 16 ++++++++++------ .../EventBus/Rebus/AbpRebusEventBusOptions.cs | 6 +++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/AbpEventBusRebusModule.cs b/framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/AbpEventBusRebusModule.cs index ad5ac9ecde..4e101f7f95 100644 --- a/framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/AbpEventBusRebusModule.cs +++ b/framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/AbpEventBusRebusModule.cs @@ -1,8 +1,10 @@ using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; using Rebus.Config; using Rebus.Handlers; using Rebus.Pipeline; using Rebus.Pipeline.Receive; +using Rebus.ServiceProvider; using Volo.Abp.Modularity; namespace Volo.Abp.EventBus.Rebus; @@ -16,11 +18,12 @@ public class AbpEventBusRebusModule : AbpModule context.Services.AddTransient(typeof(IHandleMessages<>), typeof(RebusDistributedEventHandlerAdapter<>)); var preActions = context.Services.GetPreConfigureActions(); - Configure(rebusOptions => + var rebusOptions = preActions.Configure(); + Configure(options => { - preActions.Configure(rebusOptions); + preActions.Configure(options); }); - + context.Services.AddRebus(configure => { configure.Options(options => @@ -34,9 +37,9 @@ public class AbpEventBusRebusModule : AbpModule }); }); - preActions.Configure().Configurer?.Invoke(configure); + rebusOptions.Configurer?.Invoke(configure); return configure; - }); + }, startAutomatically: false, key: rebusOptions.RebusInstanceName); } public override void OnApplicationInitialization(ApplicationInitializationContext context) @@ -46,6 +49,7 @@ public class AbpEventBusRebusModule : AbpModule .GetRequiredService() .Initialize(); - context.ServiceProvider.StartRebus(); + var rebusOptions = context.ServiceProvider.GetRequiredService>().Value; + context.ServiceProvider.GetRequiredService().StartBus(rebusOptions.RebusInstanceName); } } diff --git a/framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/AbpRebusEventBusOptions.cs b/framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/AbpRebusEventBusOptions.cs index 4b93082722..8f61d8dae3 100644 --- a/framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/AbpRebusEventBusOptions.cs +++ b/framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/AbpRebusEventBusOptions.cs @@ -10,10 +10,10 @@ namespace Volo.Abp.EventBus.Rebus; public class AbpRebusEventBusOptions { - [NotNull] - public string InputQueueName { get; set; } = default!; + public string InputQueueName { get; set; } = null!; + + public string RebusInstanceName { get; set; } = "default-instance"; - [NotNull] public Action Configurer { get => _configurer; set => _configurer = Check.NotNull(value, nameof(value)); From b7ce35635fb22c739d13c3e4ff11486a0068d179 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Wed, 27 Aug 2025 17:39:49 +0800 Subject: [PATCH 2/2] Update AbpEventBusRebusModule.cs --- .../Volo/Abp/EventBus/Rebus/AbpEventBusRebusModule.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/AbpEventBusRebusModule.cs b/framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/AbpEventBusRebusModule.cs index 4e101f7f95..af42ea905b 100644 --- a/framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/AbpEventBusRebusModule.cs +++ b/framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/AbpEventBusRebusModule.cs @@ -50,6 +50,8 @@ public class AbpEventBusRebusModule : AbpModule .Initialize(); var rebusOptions = context.ServiceProvider.GetRequiredService>().Value; - context.ServiceProvider.GetRequiredService().StartBus(rebusOptions.RebusInstanceName); + context.ServiceProvider + .GetRequiredService() + .StartBus(rebusOptions.RebusInstanceName); } }