TheMagnificent11 / lewee

2 stars 1 forks source link

Dispatch domain events to a queue #139

Open TheMagnificent11 opened 7 months ago

TheMagnificent11 commented 7 months ago

Currently, an outbox pattern is used to dispatch domain events; domain events are written as JSON to the DomainEventReferences table, and a background service looks up new domain events, dispatches them and marks them as dispatched.

This happens every few seconds.

An improvements might be to leverage a post-save Entity Framework event to dispatch new domain events to a queue or service bus, probably using MassTransit (to allow the user to choose the type of queue they wish to use), and then have a worker(s)/subscriber(s) that action these domain events.

That way, dispatching doesn't need to happen using a background service that sleep for a couple of seconds before checking for new domain events.

Once dispatched to the queue, the locking and retry-logic of the queue deals with the domain events.

TheMagnificent11 commented 7 months ago

Not sure I want to do this anymore 🤔