thenativeweb / node-cqrs-domain

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

revision guard #136

Closed alemhnan closed 5 years ago

alemhnan commented 5 years ago

Hello @adrai ,

I'm trying to figure how to use the revision guard store. I am doing some tests but apparently I can't make it work.

The setup is 'correct' (at least it seems so). I try to fire manually events for a same aggregate in a different order but I never get the expected behavior.

Do you have some working examples to look at?

nanov commented 5 years ago

There is no revision-guard-store on the domain module, do you mean the saga/denormalizer implementation?

Have you set the revision property on the event definition? Otherwise events do not contain revision information and therefore no guard store is used by denormalisation, as there is nothing to guard for.

alemhnan commented 5 years ago

Yes pardon, I meant in the denormalizer module.

I indeed set the revision property, they are correctly used by the system (they are correctly increment per aggregate).

nanov commented 5 years ago

The store works ( in inmemory mode ) out of the box, what is the behaviour you expect?

You can test it by trying the following, set a denormalizer, handle and event with some context aggregate and some stream Id with revision 1 afterwards handle an event with the same parameters but with revision 5 you should get a missing event notification after some time ( the guardStore waits for some time for the missing events to arrive before firing a missing events event ).

Bear in mind, that the current implementation guards the revisions of the same stream ( ie same aggregate id and type from the same context ) and not globally.

alemhnan commented 5 years ago

I tried to trigger an error to see if it's was working cause I had the suspicion it was not doing anything. I used the mongodb implementation but it did not created any db at all.

I will try again to trigger an error to see if it's working with your suggestion (I was trying an out-of-order event scenario).

I noticed that in the cqrs-sample the name of the parameter used in the denorm options is revisionGuardStore, while the correct one is actually revisionGuard. Even using the correct one I still do not have the db created.

I'll set up a better test and let you know if I still have problems.

nanov commented 5 years ago

I would first verify that everything works as expected in inmemory mode, the default settings, without setting a thing. The test should do everything in the same run, hence there is no persistence.

Then i would worry about the persistence mode.

alemhnan commented 5 years ago

Ok, I got it.

After some digging I've figured out that I did not have correctly defined the aggregateId property. I had that correctly defined in the domain, not in the denormalizer.

Thanks for the help.