RRPC supports calling custom topics so that devices can communicate with the cloud. A communication topic contains the entire custom topic.

Topic formats

The format of a topic for RRPC is as follows:

  • Request topic: /ext/rrpc/${messageId}/${topic}
  • Reply topic: /ext/rrpc/${messageId}/${topic}
  • Subscription topic: /ext/rrpc/+/${topic}

In the preceding formats, ${messageId} indicates the message ID generated by IoT Platform, and ${topic} indicates the topic you created.

RRPC connection

  1. Connect the device to the cloud SDK.

    Call the RRPC API to connect your device to the cloud SDK. For more information about the call method, see RRPC.

    The following example uses the Java SDK for the call method:

    RRpcRequest request = new RRpcRequest();
    request.setProductKey("testProductKey");
    request.setDeviceName("testDeviceName");
    request.setRequestBase64Byte(Base64.getEncoder().encodeToString("hello world"));
    request.setTopic("/testProductKey/testDeviceName/get");//If you want to use your custom topic, enter the custom topic.
    request.setTimeout(3000);
    RRpcResponse response = client.getAcsResponse(request);

    To use a custom topic, make sure that your Java SDK (aliyun-java-sdk-iot) version is 6.0.0 or later.

    <dependency>
        <groupId>com.aliyun</groupId>
        <artifactId>aliyun-java-sdk-iot</artifactId>
        <version>6.0.0</version>
    </dependency>
  2. Connect the device to the cloud.

    If you want the cloud to send RRPC call requests to the device using a custom topic, when you configure the MQTT communication protocol you must add the parameter ext=1 into clientId. For more information, see Establish MQTT over TCP connections.

    For example, the original clientId that the device sends is as follows:

    mqttClientId: clientId+"|securemode=3,signmethod=hmacsha1,timestamp=132323232|"

    After ext=1 is added to the clientId, the clientId that the device sends is as follows:

    mqttClientId: clientId+"|securemode=3,signmethod=hmacsha1,timestamp=132323232,ext=1|"
    Note If you use RRPC to establish communication between your devices and the cloud, and you use a custom topic, make sure that:
    • The topic variable in the message that is sent from the cloud is not empty.
    • The parameter ext=1 is added into clientId.
  3. Return the reply topic.

    The request topic can be used as the reply topic because the format of the reply topic is the same as that of the request topic, and the messageId is not extracted.