Background
Requester: a Publisher client that publishes messages carrying ResponseTopic and Correlation Data;
Responder: a client that subscribes to and processes messages. For messages carrying ResponseTopic and Correlation Data properties, it generates response messages (with TopicName set to ResponseTopic) and sends them back to the MQTT Server for further processing by the Requester or other subscribers based on business logic;
For MQTT v5.0 Publishers and Subscribers, Request Response can be implemented based on the protocol and business requirements. For legacy devices that only support v3.1 and v3.1.1, the Request Response proxy reply feature is needed to provide a unified approach.
Implementation Principles
If the Requester uses the v3.1 or v3.1.1 protocol, it can use message enhancement rules to dynamically add MQTT 5.0-defined properties such as Response Topic and Correlation Data on the server side; For v3.1 and v3.1.1 Responders, after enabling automatic reply, the processing flow is as follows:
After receiving PubAck/PubComp from a low-version Responder, the server generates a reply message based on a predefined template, carrying CorrelationData, and sends it to the ResponseTopic specified by the Requester.
Usage Instructions
1. The Responder Subscriber must subscribe with QoS > 0.
2. Auto Response automatically generates and publishes response messages only for messages that remain QoS > 0 after QoS downgrade.
3. By default, the MQTT Server enables automatic reply only for MQTT v3.1 and v3.1.1 Responders. v5.0 clients should implement Request Response on their own according to the protocol specifications.
4. Automatic reply message details:
Topic Name: ResponseTopic property value of the original message
CorrelationData: Correlation Data value of the original message
Message body in JSON format, containing the following fields:
|
id | Stores the unique message identifier |
instanceId | Instance ID |
publisherClientId | Requester client identifier |
subscriberClientId | Responder client identifier |
subscriberUsername | Responder username |
subscriberClientHost | Responder Client Host |
topic | Topic Name of the original message |
qos | QoS for delivery to Responder |
pubProps | Properties for publishing to Responder |
messageReceivedAt | Time when the MQTT Server receives the Requester Publish packet, in milliseconds since epoch |