ASP Web-API with MessageBroker - Post was processed, what now?
I'm trying to seperate the ASP Web-API from the workers which interact with the daterbase using RabbitMQ as MessageBroker. Im starting with a CRUD.
So the controller got the postrequest, a message was created and and the consumer (worker) saved the object in the db. But the Web-API is supposed to return the Id of the saved object or some error if the worker failed.
So how does it get the id from the worker?
Should a create a 2nd massage in the worker and make the API-Project subscribe to it?
Am i supposed to build this more like CQRS and just inform the User with 200, the post-request was received and inform him again later when the request was processed using a different microservice?
4 Replies
The latter is usually the approach I use
If you wait for a response, you kind of lose the benefit of asynchronous messaging
In a JS-Client context, you could return a 200 for the post and deliver the concrete result through websockets or long polling
In an api context, you could initially return a correlation ID you will later save the result of your operation with, so the client can fetch it at a later point in time
My first thought was a Service with SignalR that subscribes to the messages from the workers and a JS client that listens to that hub when sending a post
Yep, that's a good approach
Thanks.