- ABP Framework version: v5.1
- UI type: MVC
- DB provider: EF Core / MongoDB
- Tiered (MVC) or Identity Server Separated (Angular): yes (Micro Service)
We are able to use RabbitMQ & Service Bus as Distributed Event Bus Individually in our Microservice solution. But we would like to have a Switch between RabbitMQ or Service Bus based on tenant. Do we have any Resolver to do this out of the box?
If we are injecting both modules i.e. 'AbpEventBusRabbitMqModule' and 'AbpEventBusAzureModule' by default it's only picking RabbitMQ.
Is their any kind of extension method available for switching between Distributed Event Bus. Please advise.
6 Answer(s)
-
0
Hi,
You can inject
RabbitMqDistributedEventBus
andAzureDistributedEventBus
instead ofIDistributedEventBus
-
0
Hi,
You can inject
RabbitMqDistributedEventBus
andAzureDistributedEventBus
instead ofIDistributedEventBus
but based on which condition it will pick the relevant one?
Also we we mentioned earlier If we are injecting both modules i.e. 'AbpEventBusRabbitMqModule' and 'AbpEventBusAzureModule' by default it's only picking RabbitMQ.
-
0
Is their any kind of extension method available for switching between Distributed Event Bus. Please advise.
No, we don't have such an extension, The event bus is designed to use only one implementation at the same time.
Also we we mentioned earlier If we are injecting both modules i.e. 'AbpEventBusRabbitMqModule' and 'AbpEventBusAzureModule' by default it's only picking RabbitMQ.
As I said, you can inject
RabbitMqDistributedEventBus
andAzureDistributedEventBus
instead ofIDistributedEventBus
,In this way, you can publish your own event to different event bus. but it's not perfect,。
Just an idea, you can create a hybrid event bus implementation class.
For example:
[ExposeServices(typeof(IDistributedEventBus), typeof(MyHybridEventBus))] public class MyHybridEventBus : DistributedEventBusBase { private readonly RabbitMqDistributedEventBus _rabbitMqEventBus; private readonly AzureDistributedEventBus _azureEventBus; protected MyHybridEventBus( IServiceScopeFactory serviceScopeFactory, ICurrentTenant currentTenant, IUnitOfWorkManager unitOfWorkManager, IOptions<AbpDistributedEventBusOptions> abpDistributedEventBusOptions, IGuidGenerator guidGenerator, IClock clock, IEventHandlerInvoker eventHandlerInvoker, RabbitMqDistributedEventBus rabbitMqEventBus, AzureDistributedEventBus azureEventBus) : base(serviceScopeFactory, currentTenant, unitOfWorkManager, abpDistributedEventBusOptions, guidGenerator, clock, eventHandlerInvoker) { _rabbitMqEventBus = rabbitMqEventBus; _azureEventBus = azureEventBus; } public override async Task PublishAsync(Type eventType, object eventData, bool onUnitOfWorkComplete = true) { if (await ShouldPublishToRabbitMqAsync()) { await _rabbitMqEventBus.PublishAsync(eventType, eventData, onUnitOfWorkComplete); } if (await ShouldPublishToAzureAsync()) { await _azureEventBus.PublishAsync(eventType, eventData, onUnitOfWorkComplete); } } private Task<bool> ShouldPublishToRabbitMqAsync() { ... } private Task<bool> ShouldPublishToAzureAsync() { ... } }
-
0
Thanks, will give a try and update you. Thanks
-
0
We are still checking will update you ASAP
-
0
ok.