MQTT can be used to implement Request / Response behavior.

We plan to use MQTT to deliver messages from our server to Android devices, we decided to go open source mosquitto.

in most cases, this is enough. (Publishing / subscribing) but we have cases where the client needs to send parameters and receive a response from the server. I know that a direct approach is to use Http (e.g. servlets). but can we achieve this with MQTT, as that would mean lower bandwidth consumption for the user?

+4
source share
2 answers

Yes, it just requires careful design of your theme structure. As a very simple example, you can post to control/<client id>/request and subscribe to control/<client id>/response

+7
source

I recommend that you watch how RabbitMQ handles RPC . Despite the fact that AMQP differs from MQTT, quite a lot is transferred to a high level.

You do not need to create ephemeral "Reply To" queues with correlation identifiers using message headers. Or as @ralight said that there are two lines open for each client. The problem with the two queues, open for each client, is of course ordered, and therefore you will have to use correlation identifiers, as well as a buffer and a route inside (or drop to the correlation identifier if your application is synchronous).

+2
source

All Articles