New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get uncommitted events without empty the aggregate #441
Comments
In my opinion neither should be preferred. For a couple reasons:
That being said, if you really feel like you need to be able to read the events, it should be pretty trivial to maybe add an interface to your app, something like |
Thanks @wjzijderveld
But that being said, to implement outbox pattern:
Solution 3
|
I'm still not sure why projectors are relevant here. If your outbox happens first or last in the event listener chain shouldn't make any difference right? Your 3rd solution sounds like a good option for what you want, besides a bit convoluted for what you need. Two other options to consider: wrapping either the event store or the event bus and add your outbox logic in there. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Sometimes there is a need to obtain the uncommitted events from the aggregate without emptying it. Today, the implementation of the
EventSourcedAggregateRoot::getUncommittedEvents()
method, works by emptying the array:A current scenario where I need to obtain the event stream is in the implementation of the outbox pattern, in which I need to send the events to a db recording system and then send them to an external microservice. Let's consider this example:
I need to dispatch the events after saving to be sure that saving has worked well, as well as all projectors have done their job. However, this snippet of code cannot run because the call to $user->getUncommittedEvents() will empty the events inside the aggregates.
So, I wonder if this kind of behavior is mandatory. Or if you have ever thought about a different approach.
I have considered two possible solutions without modifying the current implementation:
Solution 1
Using
PublicConstructorAggregateFactory
to recreate aggregate passing to it the extracted event stream:Solution 2
Implement the outbox pattern through a traditional
Broadway\EventHandling\EventListener
but this solution has a big problem: I can't guarantee that the "outbox event listener" be performed last. So this solution is automatically trashed.What do you think about my situation? Can I use the solution 1? Or can we do something in the current implementation?
The text was updated successfully, but these errors were encountered: