C
C#10mo ago
M B V R K

Why Events Inserted Twice by EF Core?

Hi guys hope you're doing well, I'm working on the following project : https://github.com/MbarkT3STO/ExpenovaApp This project implemented using Microservices Architecture I have a service called Event-Sourcerer Service, this service is responsible about applying event-sourcing for others services databases records, of course this services communicate with others using RabbitMQ and MassTransit. You can take a look on that service here : https://github.com/MbarkT3STO/ExpenovaApp/tree/main/Source/EventSourcererService This service contains some Message Consumers ( classes where each one responsible to consume/handle a specific Queue's messages ). This service uses EF Core with PostgreSQL as data persistence. After a Servie X published an Event that happened in it, and the Event Handler from that Service X will publish a copy of that event as a Message to RabbitMQ then the Consumers from the Event-Sourcerer Service will do their job by adding the message they are responsible for into the Event-Sources database. The issue: Is my consumers adding the event to database twice To fix this issue I have created a service to handle the Deduplication mechanism as separated class called DatabaseMessageDeduplicationService you could take a look at it here : https://github.com/MbarkT3STO/ExpenovaApp/blob/main/Source/EventSourcererService/Services/DatabaseMessageDeduplicationService.cs That class DatabaseMessageDeduplicationService is responsible about processing messages too. So, for proccessing messages this class contains a method called ProccessMessage as following:
public async Task ProcessMessage(Expression<Func<Task>> processMessageFunc)
{
await processMessageFunc.Compile().Invoke();
}
public async Task ProcessMessage(Expression<Func<Task>> processMessageFunc)
{
await processMessageFunc.Compile().Invoke();
}
This method take a func/method from a consumer, that method consumer will contains the code to process the message and this DatabaseMessageDeduplicationService only invoking it.
2 Replies
M B V R K
M B V R KOP10mo ago
But the issue is the events get stored twice The follwing is an example of a Message Consumer: Please take a look at this video too, to get the issue https://ufile.io/o8h27pdq My guess is the issue because of the Classes Inheritance but idk if that's true or not I hope someone here to provide a help if he get the issue And massive thanks in advance 3
M B V R K
M B V R KOP10mo ago
Please take a look here to see this consumer's definition:
Want results from more Discord servers?
Add your server