nestjs / docs.nestjs.com

The official documentation https://docs.nestjs.com 📕
MIT License
1.18k stars 1.68k forks source link

Provide production level example #957

Open raymondsze opened 4 years ago

raymondsze commented 4 years ago

It is not reasonable to use In-memory eventBus for doing cqrs in production. Instead, we should use some message broker system for eventBus like Kafka.

There are some questions in my mind.

  1. Although we could somehow switch the defaultPubSub to other mechanism like Kafka or something else, the underlying is using Rxjs observer pattern. What I currently do is switch the defaultPubSub to my customised PubSub. Run a kafka consumer in the defaultPubSub, and what I do inside is just subject$.next(event). To do so, I need to guarantee the event-handler have successfully response to the event then commit the offset, but how could I do that without changing the code in EventBus?

  2. I would like to implement a Saga Orchestrator pattern that to manage distributed transaction. But the saga is implemented by observer pattern as well. Again I need to guarantee the saga have successfully response to the event then commit the offset, how could I do that? I think Saga is just like a special kind of aggregate, which should have its own state as well. So saga is also just an event-handler that it could make use of commandBus to send command.

So, to summarise, is that using RxJs a correctly way to implement cqrs system? And I think really need some "production" level example that using nestjs/cqrs.

Thanks.

Stoom commented 3 years ago

@raymondsze Have you made any progress on this? I'm trying to swap in the eventstore node package for this as it interfaces with a lot of databases. I'm confused on how to ever change the default publisher. I see the method to set the publisher in the EventBus, but with how it's registered with nestjs, I'm not quite sure how to call it.

kodeine commented 3 years ago

Any updates on this?

delucca commented 3 years ago

Have anyone managed to do something like this? I've found some libraries, but no reasonable example. I'm considering using NestJS in my new CQRS application, but this requirement (storing events in an event store) is mandatory.

Actually, not having this feature loses almost the entire purpose of event sourcing at all.

FBurner commented 3 years ago

Is this considered?

KieronWiltshire commented 2 years ago

Is there an update on this? How does saga compensation work in NestJS?