Comments (6)
I replicated this issue on Nest main repo, as I'm not sure anyone is looking at issues here...
from cqrs.
Hi @sebastiendan,
You could create a separate class which isolates a Subject
instance inside. Once UserProfile
has been successfully created, you can use this class to call .next()
on the underlying Subject
which in turn is being used before your authService
call, like:
const { authUser } = await this.authService.createAuthUser(createUserDto);
await this.notifierSubject.pipe(first());
also, you can bubble error up as well and then handle it through this extra Rx stream:
await this.notifierSubject.pipe(
first(),
catchError(....),
)
However, I think that the main problem here is raising events from different application's instances in the distributed environment, correct? In this case, replace your Subject
with some sort of pub/sub transporter (for instance Redis) to transfer events between different pods.
from cqrs.
@kamilmysliwiec Didn't think of using a Subject here... It's probably a very easy way to manage a transactions flow. However, I don't see the point now to use CQRS... I could just use a Subject instance, subscribed by all my transaction endpoints (User creation, User deletion, etc.) to keep the flow clean and sync. For instance, the Subject could hold a "state" object with an id for the current step and a payload for data identification transportation (User id is needed for User Profile creation).
The main problem isn't really dealing with multiple nodes on my app, it's really just about ordering and managing a set a transactions that need to react to each other.
I thought CQRS was the right answer for that challenge, but maybe I was wrong (plus it adds so much boilerplate...).
What do you think?
from cqrs.
Alright, it seems that I misunderstood your issue. In this case, you can add two extra events that would indicate either success or failure of User Profile creation. Then, you could inject EventBus
and subscribe to both events (using, let's say, ofType()
+ merge()
operator). The failure event would mean that the whole transaction wasn't successfully completed (and then, simply mergeMap
into error stream with an HTTP exception).
from cqrs.
Thanks for this solution. I'm currently working on a different project but I'll have to use soon the same logic so I'll give it a try.
I've got to say though that the idea of a global Subject instance + web sockets/sse to send real time status of transactions to clients is something that might be a more interesting, easier to develop and lighter solution for this topic (compared to CQRS).
Thanks @kamilmysliwiec ! And congrats for the awesome work on Nest. I'm glad it's getting greater attention every week (doing some promotion to big players here in Tokyo!).
from cqrs.
Thank you @sebastiendan, fingers crossed 🤞 Keep me updated 🇯🇵
from cqrs.
Related Issues (20)
- TypeError: You provided 'undefined' where a stream was expected HOT 2
- Middleware chain for command and querybud HOT 2
- Saga events - request context HOT 1
- documentation request HOT 1
- problems constructing instance with Mikro ORM HOT 1
- Feat: Register Commands, Queries & Events programatically HOT 1
- Multiple execution of events based on how many times module is imported HOT 1
- Adjust EventsHandler typing to accept the type of class extending IEvent
- Double events when using microservice HOT 2
- Sagas stop working in case of exceptions HOT 2
- Command handler becomes unresponsive HOT 4
- Event Handler fails to Trigger After Error Occurs HOT 1
- Use a decorator to automatically merge event publisher into AggregateRoot HOT 1
- Http Exceptions thrown in certain situations cause an app crash. HOT 1
- App crashes if event handler triggers a command that throws HOT 1
- CommandHandleException with Command Name not command uuid HOT 2
- Commit method throws an error when trying to publish domain events HOT 1
- Patch update reflect-metadata HOT 1
- Request scope or an alternative for multitenancy, using CQRS module
- Cannot read properties of undefined (reading 'id') - possible breaking change for 8.0.1 HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cqrs.