Open Closed

Pre-Defined Events with multiple replicas in microservices architecture #9173


User avatar
0
triet.nguyen created

Hi,

I have a solution to synchronize the cache for a service within a microservices architecture. I have successfully integrated with the IdentityService to receive notifications whenever a User or OrganizationUnit is created, updated, or deleted.

However, the service subscribes to the IdentityService, which runs on three replicas. From my observations on my local machine using Minikube, only one instance receives the event, not all instances.

Could you provide me what is the best approach in ABP framework that supports my case?

Note: We are using RabbitMQ as the message queue.


2 Answer(s)
  • User Avatar
    0
    enisn created
    Support Team .NET Developer

    Hi,

    It's by design. The event handler is executed only once to prevent concurrent write operations at the same time.

    It's the defaults of RabbitMQ. It uses kinda load-balancing operation across the subscribers and sends the event to only one single instance and awaits acknowledge (ACK) info to complete the event. If not, tries to send it again. It's the expected behaviour.

    If your intent is for all instances to receive the event (for example, for broadcasting purposes), you’ll need to change the design slightly. A common approach is to use a publish/subscribe pattern with a fanout exchange. In this configuration, each service instance can have its own dedicated queue bound to the fanout exchange. Every time a message is published to the exchange, each bound queue gets its own copy of the message, and thus every instance can process it independently.

    ABP Framework doesn't implement this fanout exchange logic since it's coupled to RabbitMQ and ABP uses abstraction over event-buses. That mean, you'll need to implement it on your own by using the RabbitMQ library itself instead using ABP abstractions.

  • User Avatar
    0
    enisn created
    Support Team .NET Developer

    ABP has an option for making ExchangeType as Fanout but it applies globally for the application. That means you can make it for all the events, not a particular event.

    Configure<AbpRabbitMqEventBusOptions>(options =>{
        options.ExchangeType = ExchangeType.Fanout;
    });
    

    You'll need to configure it both published and subscriber applications.

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
Do you need assistance from an ABP expert?
Schedule a Meeting
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v9.3.0-preview. Updated on May 12, 2025, 05:22