node-cqrs-eventdenormalizer icon indicating copy to clipboard operation
node-cqrs-eventdenormalizer copied to clipboard

write to different repositories for the same definition of the viewbuilder

Open daschy opened this issue 7 years ago • 6 comments

In the same node instance I have:

  • 1 view builders (vb)
  • 2 mongo repositories: repomongoCustomer1, repomongoCustomer2
  • 2 denormalizers: - denomCustomer1 (that writes to repomongoCustomer1),
    • denomCustomer2 -> (that writes to repomongoCustomer2),
  • 1 eventstore. Each event in the eventstore contains a property customer that describes what denormalizer is in charge of the denormalization.

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 avatar Jan 26 '18 13:01 daschy

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.

daschy avatar Jan 26 '18 14:01 daschy

So it’s fine for you?

adrai avatar Jan 26 '18 18:01 adrai

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?

daschy avatar Jan 28 '18 20:01 daschy

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 avatar Jan 29 '18 05:01 adrai

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

adrai avatar Jan 29 '18 05:01 adrai

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.

daschy avatar Jan 29 '18 15:01 daschy