thenativeweb / node-cqrs-eventdenormalizer

Node-cqrs-eventdenormalizer is a node.js module that implements the cqrs pattern. It can be very useful as eventdenormalizer component if you work with (d)ddd, cqrs, domain, host, etc.
http://cqrs.js.org/pages/eventdenormalizer.html
MIT License
38 stars 27 forks source link

viewbuilders not ordering properly #48

Closed pawarvijay closed 8 years ago

pawarvijay commented 8 years ago

hie :)

what i am trying to achieve : i create sales invoice and related to sales invoice i create accounting entries and if there is problem in creating accounting entries then i want to cancel sales invoice created earlier.

on salesInvoiceCreated event

  1. salesInvoiceCreated viewbuilder executes and creates readmodel
  2. salesInvoiceCreatedSaga.js listens and creates command createAccounting.
  3. i forcefully generated error in businessrule of createAccounting so that it will throw rejectedCommand event
  4. on rejectedCommand event it will fire cancelSalesInvoice

my sample with context and saga implemented

problem: some times every thing works fine it creates sales invoice then and on problem in creating accounting entries it cancels sales invoice created earlier and keeps giving AlreadyDenormalizedError error but but but some times cancel sales invoice fires first and then create sales invoice and keeps giving AlreadyDenormalizedError error

solutions that i tried : also i tried to set priority in viewbuilder

adrai commented 8 years ago

priority in viewbuilder only guaranties order for same event on multiple viewBuilders

what you need is having just 1 aggregate that generates these events, or try to use the "retry" function in the viewbuilder

pawarvijay commented 8 years ago

your module works properly actually problem was : if PostgreSQL make update faster, update will return result before insert