Browse Source

Start Rebus after RebusDistributedEventBus is initialized

pull/23613/head
liangshiwei 5 months ago
parent
commit
cca79a13b4
  1. 16
      framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/AbpEventBusRebusModule.cs
  2. 6
      framework/src/Volo.Abp.EventBus.Rebus/Volo/Abp/EventBus/Rebus/AbpRebusEventBusOptions.cs

16
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<AbpRebusEventBusOptions>();
Configure<AbpRebusEventBusOptions>(rebusOptions =>
var rebusOptions = preActions.Configure();
Configure<AbpRebusEventBusOptions>(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<RebusDistributedEventBus>()
.Initialize();
context.ServiceProvider.StartRebus();
var rebusOptions = context.ServiceProvider.GetRequiredService<IOptions<AbpRebusEventBusOptions>>().Value;
context.ServiceProvider.GetRequiredService<IBusRegistry>().StartBus(rebusOptions.RebusInstanceName);
}
}

6
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<RebusConfigurer> Configurer {
get => _configurer;
set => _configurer = Check.NotNull(value, nameof(value));

Loading…
Cancel
Save