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

write to different repositories for the same definition of the viewbuilder #71

Open daschy opened 6 years ago

daschy commented 6 years ago

In the same node instance I have:

When I instantiate, in order, denomCustomer1 and denomCustomer2. Happens that the event is only written to the last repository (repomongoCustomer2) .

Is it possible to have multiple repository associated to multiple denormalizers, all created from the same viewBuilder?

Thanks

daschy commented 6 years ago

Just an update. I tried to duplicate the view builders, so now I have vbCustomer1 and vbCustomer2 and works as expected. It save the data to each repository correctly.

adrai commented 6 years ago

So it’s fine for you?

daschy commented 6 years ago

No really, in this way everytime I need to add a customer I have to duplicate the files, it can only be done by taking the server down. Is there another solution, without physically duplicating the files?

adrai commented 6 years ago

Not right now... But open for a PR 😊 Perhaps a new function in the viewBuilder that verifies an prepares a repository by analyzing the event... Or a new type of collection (a dynamic collection)

adrai commented 6 years ago

You only need a new collection on-the-fly right? Not a complete new db...

daschy commented 6 years ago

I don't think that collection on the fly is what I need. I need the entire database everytime.

The use case is every time I do, on the same node instance:

const denormCustomer1 = new Denorm ({viewBuilder, repomongoCustomer1});
const denormCustomer2 = new Denorm ({viewBuilder, repomongoCustomer2})
msgbus.onEvent(event => {
        if ('customer1'=== event.data.customer) {
          denormCustomer1.handle(event);
        }else if ('customer2'=== event.data.customer) {
          denormCustomer2.handle(event);
       }
 });

It denormzalizes to repomongoCustomer1 or repomongoCustomer2 based on the info based on the event.