Open Closed

Is their any kind of extension method available for switching between Distributed Event Bus #3362


User avatar
0
viswajwalith created
  • 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)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    You can inject RabbitMqDistributedEventBus and AzureDistributedEventBus instead of IDistributedEventBus

  • User Avatar
    0
    viswajwalith created

    Hi,

    You can inject RabbitMqDistributedEventBus and AzureDistributedEventBus instead of IDistributedEventBus

    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.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    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 and AzureDistributedEventBus instead of IDistributedEventBus,

    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()
        {
            ...
        }
    } 
    
  • User Avatar
    0
    viswajwalith created

    Thanks, will give a try and update you. Thanks

  • User Avatar
    0
    viswajwalith created

    We are still checking will update you ASAP

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    ok.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 13, 2024, 06:09