Problem on calling a "Command" in the Denormalizer event...

34 views
Skip to first unread message

Gorton Zhao

unread,
Dec 15, 2014, 10:45:01 PM12/15/14
to ncqr...@googlegroups.com
According to NCQRS documentation, a command should usually update the ReadModel database or call a remote service via the Denormaliser (events). Can I call another command inside the Denormalizer event method? 

It does not seem me to be able to do it as the NCQRS throws the exception says that there is already a unit of work created for this context when I do this. What I am going to do is to create three Commands (MakePayment, CompletePaymentProcess and RecordPaymentProcessError). In the Denormalizer event of MakePayment command, I will call CompletePaymentProcess command if it is successful, otherwise I will call RecordPaymentProcessError command. The reason for calling this two commands is just for having the process results stored in the event table. How would you suggest to do with this in NCQRS?

Thanks and regards, Gorton

Galen Parker

unread,
Dec 16, 2014, 4:05:38 AM12/16/14
to ncqr...@googlegroups.com
 Can I call another command inside the Denormalizer event method? 

Nope. Don't do this.

* Design your denormalizers so they are replay friendly. Thats one of the big perks of CQRS is the ability to replay the events and generate new or modified read models. Having your event handlers issue commands (that generate more events) removes this characteristic.


There is another way which is possible using Ncqrs.Messaging that allows your aggregates to dispatch "Messages" (that act like commands) to other aggregates.

I had much trouble with this approach and ended up abandoning the entire concept of "ncqrs aggregates" issuing command like messages.

Instead I switched over to NServiceBus based Sagas/Process Managers that act as my Bounded Context and Aggregate messaging orchestrators.

For example I have a process manager called:   PendingOrderApprovalProcess

This saga listens for EVENTS generated by my domain and handles the construction ,ordering and dispatching of related commands to fulfil the process of approving an order.

Even tho the Saga is an event handler, you should have this in a seperate concept seperate to your read model denormalizers. (Obviously replaying events should not re-run the PendingOrderApprovalProcess).

I hope this helps.

Galen

--
You received this message because you are subscribed to the Google Groups "ncqrs-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ncqrs-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--

Galen Parker
Chief Technology Officer
Landlord Central Pty Ltd

 

 

Telephone: (02) 8006 1979
International: +612 8006 1979
Mobile: 0418 900 192
Fax: (08) 9463 7818

Skype: property.compass

Twitter
LinkedIn

Contact me: Skype galen.parker
Reply all
Reply to author
Forward
0 new messages