jeudi 21 mars 2019

Is there a pattern for synchronizing message queue communication to request/response manually?

Let's imagine I have a REST API with an endpoint /api/status. When this endpoint is accessed, the API sends a message to a message queue requesting the status of some other service.

Then in reply, the service sends a message with its status to a queue on which the REST API listens. So it's single message to request the status and single reply message.

My question is: Is there a design pattern for converting the asynchronous nature of this approach to a synchronous one in the API? In other words: Is there a pattern that the GetStatus(...) method in the pseudo code below can implement to synchronize the getting of the status with communication over multiple message queues or even pub/sub systems.

var statusRequestMsg = "get_status";
var statusResponseMsg = GetStatus(statusRequestMsg);

I know how to solve this in code but I was curious if there is a design patter that introduces a common approach.

I googled a lot in search for that but the only think that I found was a very technical explanation of an approach to do that in this article: A Communication Model to Integrate the Request-Response and the Publish-Subscribe Paradigms into Ubiquitous Systems

Please note that I understand that this is not the perfect API design and that there are better ways to implement the example. I've created the above example to help me illustrate my question. Also I understand that some AMQP impl. (like RabbitMQ) provide a way to synchronize MQ communication to request/response style.

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire