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
Event Handler / Saga / Where to Write Documentation #64
Comments
As I've continued on in my ES/CQRS learning I've become more familiar with the patterns so where to do a write is not so elusive now. It looks like people want to expand the official NestJS CQRS example, so maybe I can make some suggestions on that project while I'm continuing to learn. Cheers 🍻 |
how using to rollback transaction in cqrs and event sourcing, in sagas when have event failed or message broker failed. Thanks all |
@jsonberry i'm in the same boat as you were a while ago, could you please confirm if i'm following the right pattern. Account has many users. User App: CreateUserCommand -> write to db, result goes to aggregate -> commit() -> UserCreatedEvent Account App: Saga ofType UserCreatedEvent -> use the userId from event send new command -> CreateAccountCommand i'm not using UserCreatedEventHandler here... should i be doing writes in there? so what needs to happen in command handler then... |
Your pattern sounds logical, for this case either an event handler or a
Saga could work...
I would go with a Saga, because you know the next step in the flow is a
command (create account), and Sagas always end in a command being issued.
Sagas are my goto as a way to orchestrate events with commands. Their most
powerful feature IMHO is the async behavior via RxJS, when I needed to fire
off commands and then wait for success/failure events inside the same saga
to continue processing...(that’s how I handle rollback type features).
I have ended up using Event Handlers often, and I usually designated them
to encapsulate logic where a write to an aggregate or the storage of event
wasn’t going to happen... basically like side effects... logging, email/sms
notifications, sending events to other systems event pipelines like an AWS
SQS queue. They’re great for that stuff.
…On Tue, Jan 12, 2021 at 9:08 PM Kodeine ***@***.***> wrote:
@jsonberry <https://github.com/jsonberry> i'm in the same boat as you
were a while ago, could you please confirm if i'm following the right
pattern.
Account has many users.
User App: CreateUserCommand -> write to db, result goes to aggregate ->
commit() -> UserCreatedEvent
Account App: Saga ofType UserCreatedEvent -> use the userId from event
send new command -> CreateAccountCommand
i'm not using UserCreatedEventHandler here... should i be doing writes in
there? so what needs to happen in command handler then...
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#64 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAXQSKBC2JQEM5DKZUML52LSZUTEFANCNFSM4HD7I52A>
.
|
I'm submitting a...
My main concern is understanding a good place where to do
writes
.I'm enjoying setting up the CQRS module in my current project, but I ended up dropping event handlers because I couldn't justify a real good use for them.
From
command
handlers I am publishing events with theeventBus
, then creatingsagas
for events and additional command handlers for those because I want to:saga
levelI chose this approach so that I can onboard others into the project and if they have questions about where to do writes/reads/more complex async logic, I can direct them as such:
Am I missing something real obvious about event handlers? I fully understand I can inject into them and I can handle write logic there, but is there something better about the pattern that I am not groking?
Thanks!
Edit
I realize after reading/watching more about CQRS that this is probably just me needing to understand the pattern better.
For most of my use cases, especially for single transactions that don't require communication with other aggregates, I see that an
Event Handler
is a good place to do work. Transitioning to aSaga
seems to come into play when there are multiple transactions that need to occur, but even then at the end of theSaga
I'm not sure what I would need to do in theCommand Handler
at the end of aSaga
if I'm executing transactions inside of theSaga
.The text was updated successfully, but these errors were encountered: