node-cqrs-eventdenormalizer
node-cqrs-eventdenormalizer copied to clipboard
write to different repositories for the same definition of the viewbuilder
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
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.
So it’s fine for you?
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?
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)
You only need a new collection on-the-fly right? Not a complete new db...
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.