nestjs / event-emitter

Event Emitter module for Nest framework (node.js) 🦋
https://nestjs.com
MIT License
193 stars 37 forks source link

How does it differs from CQRS EventBus ? #44

Closed scorsi closed 3 years ago

scorsi commented 3 years ago

Hello,

I would like to understand how does it differs from the EventBus of the @nestjs/cqrs package ?

As I'm currently starting a new project with CQRS, I wanted to know if it was better using the @nestjs/event-emitter package with @nestjs/cqrs or does it didn't adds added value. What about stability/scalability/... ?

I understand the underlying system changes.

Thanks,

kamilmysliwiec commented 3 years ago

Please, use our Discord channel (support) for such questions. We are using GitHub to track bugs, feature requests, and potential improvements.

scorsi commented 3 years ago

Ok thanks. To track the question: https://discord.com/channels/520622812742811698/606125736134443011/799188866380595231

thesocialdev commented 1 year ago

It's unfortunate that this discussion is lost, I'm interested in the topic and I believe others will too.

subalee commented 1 year ago

@thesocialdev agreed.

unicornware commented 1 year ago

for those not on discord:

EventEmitter is simply an observer pattern component which means it doesn't know about any event/aggregates model logic. Anyway, CQRS bus (be it event, query or command) will allow you to execute domain-based events/commands/queries and automatically map for you the request to its handlers. If you use aggregate model, you'll notice you can commit multiple commands at once as an atomic transaction where in event-bus it reacts to an event (as it does with CQRS event listener) but doesn't allow you to apply any transaction logic before. EventEmitter is a good fit when you want to use some kind of internal pub/sub or implement and observer pattern, i would not use it when you want to implement CQRS, specially in segregation of events. If sagas/events are sufficient for you, using EventEmitter is not worth but if you just want some pub/sub internally and your app does not fit very well CQRS use case, just stick with event emitter because CQRS adds complexity - @underfisk

sidenote: it would be great if questions could be posed via github discussions!