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));