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

Event's not reaching denormalizer #1

Closed ghost closed 11 years ago

ghost commented 11 years ago

I think I'm missing something simple but I'm not sure if it's config or implementation. My issue is that I'm not seeing events reaching my denormalizer(s). I've wired in modules cqrs-domain & node-cqrs-eventdenormalizer, with basic configuration using InMemory storage/queues. I've left out all optional configuration.

In the execution sequence, everything is happening in aggregates as expected, but I'm not seeing a publish to the denormalizer. Any hints on how to wire this up would be greatly appreciated.

adrai commented 11 years ago

ok?

ghost commented 11 years ago

I decided to move on...upon further exploration of the eventdenormalizer module and docs, it looks like an explicit call is necessary to dispatch an event to the denormalizer. If I'm correct, where do you typically implement this call?

adrai commented 11 years ago

sorry I've not so much documentation at the moment...

usually domain and eventdenormalizer are on separate machines or at least processes and speaks via a messagebus myBus.on('event', function(evt) { contextEventDenormalizer.denormalize(evt); });

if you want a solution without message bus look at node-cqs

or wrap up domain and eventdenormalizer: domain.on('event', function(evt) { contextEventDenormalizer.denormalize(evt); });

for some docs look at: http://adrai.github.com/cqrs/pages/eventdenormalizer.html

ghost commented 11 years ago

No worries about lack of docs...I did try to follow along source before posting my question. Sorry if these are novice questions, I appreciate your time.

I'm following you with separate process for domain / event denormalizer, but I still don't see the how the event will published to the bus. In other implementations, I've seen this done in a repository post aggregate handling, with an explicit call like:

dummyAggregate.doSomething(); repo.save(dummyAggregate); // which looks at uncommitted events and publishes them to the event bus.

In your previous comment, is myBus.on('event')... do your modules have an implementation to announce the event to the bus?

Thanks, again.

adrai commented 11 years ago

workflow:

  1. send command to bus
  2. domain receives command: domain.handle(cmd)
  3. a commandhandler loads the appropriate aggregate and pushes the command data to it
  4. the aggregate generates one or more events and applies them to itself
  5. the commandhandler saves all generated events to the eventstore
  6. the eventstore publishes the events to the bus
  7. an eventdenormalizer process receives the events contexteventdenormalizer.denormalize(evt)
  8. one or more denormalizers denormalizes the event and saves some denormalized data in the viewmodel

this is cqrs... ;-)

ghost commented 11 years ago

Yes, I'm on the same page with you on the workflow. And it would appear that by convention the cqrs-domain module is performing #3 - #6.

However in #7, I'm not seeing the eventdenormalizer receiving the events using default configuration based on the docs provided. I've stepped through the module's execution and I see the events getting queued up for dispatch, but it appears that nothing is processing them. So my original issue stands...Is there additional configuration/wire-up to get that dispatch of events to the denormalizer to occur, or is this something I would need to implement (where do you typically do this)?

adrai commented 11 years ago

Can you give me more information? What is the last point that reaches your event? Is the event leaving the domain?

...

domain.on('event', function(evt) {
    // send to bus
    // Does your event reach this point?
});

...

// Do you pass that event to the contextEventDenormalizer?
contextEventDenormalizer.denormalize(evt, function(err) {
    // saved in event queue...
});

...

var base = require('cqrs-eventdenormalizer').eventDenormalizerBase;

module.exports = base.extend({

    events: ['dummied', {'dummyCreated': 'create'}, {'dummyChanged': 'update'}, {'dummyDeleted': 'delete'}],
    collectionName: 'dummies',

    dummied: function(evt, aux, callback) {
        // Does your event reach this point?
        callback(null);
    }

});

...

contextEventDenormalizer.on('event', function(evt) {
    // send to client, or host...
    // Does your event reach this point?
});
ghost commented 11 years ago

See my responses inline:

...

domain.on('event', function(evt) { // send to bus // Does your event reach this point? NO });

...

// Do you pass that event to the contextEventDenormalizer?

**No, I do not have this code implemented. Is this code necessary? This is confusing to me, because I see code in the domain module that seems to publish events for dispatch the eventEmitter (bus?) by convention. This is likely my problem and maybe you can explain the design of this part of the modules? If it is necessary, I don't see a good place in my app to implement this code, where do you suggest it be implemented?

contextEventDenormalizer.denormalize(evt, function(err) { // saved in event queue... });

...

var base = require('cqrs-eventdenormalizer').eventDenormalizerBase;

module.exports = base.extend({

events: ['dummied', {'dummyCreated': 'create'}, {'dummyChanged': 'update'}, {'dummyDeleted': 'delete'}],
collectionName: 'dummies',

dummied: function(evt, aux, callback) {
    // Does your event reach this point?  No
    callback(null);
}

});

...

contextEventDenormalizer.on('event', function(evt) { // send to client, or host... // Does your event reach this point? No });

adrai commented 11 years ago

ok, let's go a step back... :-)

How is your command look like? Can you show me your CommandHandler? Can you shous me your Aggregate? How is your event look like?

Can you show me a bit of your code?

ghost commented 11 years ago

git clone git://gist.github.com/4045196.git gist-4045196

adrai commented 11 years ago

git clone git://gist.github.com/4048442.git gist-4048442

ghost commented 11 years ago

Ok, I see the pieces I missed, all working now. Thanks for the help (and patience).