How to integrate RabbitMQ on a Microservice architecture

Hi guys, I have an app with a .NET back end made in multiple services, and those services are communicating with http requests, but some of them I'm waiting for a response when I do not need, I could just send to a messenger service like RabbitMQ, but there are some cases where I want to wait for a response to get data, from the videos that I watched about RabbitMQ, there wasn't one that showed how to wait for the other api's response, can someone send me some content or explain how can I implement a communication between multiple apis where I can wait for a response to get the data from it or just send a request to a queue without the need to stop the api's work?
2 Replies
Keswiik
Keswiik4w ago
Rabbit, by default, does not implement a way to 'wait' for replies to a given message. Instead, what you'll need to do is pass along another queue address with your message; it tells the recipient where to send their reply to. You'll probably want some wrapper around the logic that does this and uses an event, signal, or some other mechanism to block until the reply comes in. For my own microservices, I wrote a wrapper around rabbit that assigns a GUID to each client instance on startup. For any given transaction, it automatically formats the reply queue: SomeServiceName.Transaction.Transaction.Identifier -> SomeServiceName.Transaction.Transaction.Identifier.Reply.<client-guid> Rabbit has some docs on this use case here: https://www.rabbitmq.com/tutorials/tutorial-six-elixir
Carlos Saraiva
Carlos SaraivaOP4w ago
thank you for sharing this, I'm trying to undestand how RPC works, but it is very complicated for me, but I'll get there, thanks!

Did you find this page helpful?