The Message Queuing Telemetry Transport (MQTT) protocol uses the asynchronous publish/subscribe model. This model is not applicable to the scenarios in which user servers need to synchronously control devices and obtain responses. IoT Platform provides a synchronous communication mechanism based on MQTT. You do not need to modify the MQTT protocol. IoT Platform provides the RRpc operation for user servers to send requests to devices. The devices only need to respond to the requests by using the specified topics and then the servers can synchronously obtain the responses.
|RRPC||RRPC is short for revert-RPC. A remote procedure call (RPC) uses the client-server model. This model allows you to request a remote service without the need to understand the underlying protocol. An RRPC allows you to send a request from a server to a device and receive a response from the device.|
|RRPC subscription-specific topic||The topic to which devices subscribe to receive RRPC messages. The topic includes a wildcard.|
|RRPC request message||The message that IoT Platform sends to a device.|
|RRPC response message||The message that a device sends to IoT Platform as a response.|
|RRPC message ID||The ID that is generated by IoT Platform for each RRPC message|
- A device subscribes to the RRPC subscription-specific topic.
- A user server calls the RRpc operation.
- IoT Platform receives a server-side RRPC request and sends an RRPC request message to the device. The message body includes the payload that is sent from the user server. The topic that is used by the device to receive RRPC messages is predefined in IoT Platform. The topic includes the ID of the message.
- After the device receives the message, the device sends an RRPC response message to IoT Platform by using the specified topic. The topic includes the ID of the request message.
- IoT Platform extracts the response message ID to match the previous RRPC request message.
- IoT Platform returns the response to the user server.
- The device is offline. In this case, IoT Platform returns an error message to the user server.
- The device does not respond to the RRPC request within the timeout period (8 seconds). In this case, IoT Platform returns an error message to the user server.
You can implement RRPCs based on the following types of topics:
- Basic communication topics. For more information, see RRPC-specific topics.
- Custom topics. For more information, see Use custom topics.
For information about the example of implementing an RRPC, see Remotely control Raspberry Pi servers.