✅ Why this event published twice to RabbitMQ
Hello dear friends,
I'm working on this project (https://github.com/MbarkT3STO/ExpenovaApp)
I'm implemented this project using a complex approach that uses
DDD
, VSA
and Microservices
with CQRS
of course, the databases are implemented in PostgreSQL
using EF Core
, and as a message broker RabbitMQ
is used here by using MassTransit
.
In a service called ExpenseService
I have this CQRS
Command that updates a Category
(https://github.com/MbarkT3STO/ExpenovaApp/blob/main/Source/ExpenseService/ExpenseService.Application/Category/Commands/UpdateCategoryCommand.cs)
As you will notice that at the end of the Update operation I have published an Update Event
, publishing this event (in its handler) will publishing a message to RabbitMQ
, that message holds the data about the Category
that has been Updated,
Inside another service called EventSourcererService
(This service has created to manage the event-sourcing for data of other services), I have a MessageConsumer
called ExpenseServiceCategoryUpdatedMessageConsumer
this message consumer will recieve the message/data from RabbitMQ
's queue and he should create a new event-source for the Category
that updated in a table that used to store the events-sources related to Category
.
(https://github.com/MbarkT3STO/ExpenovaApp/blob/main/Source/EventSourcererService/MessageConsumers/ExpenseService/Category/ExpenseServiceCategoryUpdatedMessageConsumer.cs)
The issue:
The issue is that everything is working fine, but the event-source of an update operation every time inserted two times into the event-sources table.
Please take a look at the attached video to understand.
I hope someone to help getting a solution and massive thanks in advance <36 Replies
within event driven systems, exactly once delivery is an extremely hard problem. Your systems should expect multiple delivery
do you log the call to the event bus to check the code is run one time only?
did you check if there are other parts of your code where other events of that type are created?
how is the rabbit exchange/queue/binding configured?
unfortunately no, didn't add the logging functionality yet
I have checked my code idon't think if there any duplicated code or something that can make the event get published twice
You can take a look if you have time here https://github.com/MbarkT3STO/ExpenovaApp
GitHub
GitHub - MbarkT3STO/ExpenovaApp
Contribute to MbarkT3STO/ExpenovaApp development by creating an account on GitHub.
i can't look now, still you can log to the console, and if you don't have a console you can write to the debug stream or a file
did you also look in the rabbit interface to look that you had effectively two messages?
it could still be that you registered a handler twice
Alright, the issue is known in the
RabbitMQ
with MassTransit
, the solution is using a RabbitMQ
plugin that removes the Dublicated messages, or the other solution is to use a Deduplication Mechanism
, so I used the second solution by implementing my own Deduplication Mechanism
anw, massive thanks guys, I apreciate <3