How does a microservice return data to the caller when using a message broker? or a message queue?

09 Sep.,2023

 

I am prettty new to microservices, and I am trying to figure out how to set a micro-service architecture in which my publisher that emits an event, can receive a response with data from the consumer within the publisher?

From what i have read about message-brokers and message-queues, it seems like it's one-way communication. The producer emits an event (or rather, sends a message) which is handled by the message broker, and then the consumer consumes that event and performs some action.

This allows for decoupled code, which is part of what im looking for, but i dont understand if the consumer is able to return any data to the caller.

Say for example I have a microservice that communicates with an external API to fetch data. I want to be able to send a message or emit an event from my front-facing server, which then calls the service that fetches data, parses the data, and then returns that data back to my servver1 (front-facing server)

Is there a way to make message brokers or queues bidirectional? Or is it only useable in one direction. I keep reading message brokers allow services to communicate with each other, but I only find examples in which data flow goes one way.

Even reading rabbitMQ documentation hasn't really made it very clear to me how i could do this

If you have any questions on best message queue. We will give the professional answers to your questions.