tencentyun / iot-device-java

IoT Hub & Explorer 设备端 SDK (Java & Android)
https://cloud.tencent.com/product/iotexplorer
49 stars 39 forks source link

RRPC 通信接口被sdk自动回复了,无法正常进行业务 #17

Closed hendyzone closed 2 years ago

hendyzone commented 2 years ago

com.tencent.iot.hub.device.android.core.mqtt.TXMqttConnection#publishRRPCToCloud

    private Status publishRRPCToCloud(Object userContext, String processId, Map<String, String> replyMsg) {
        // 应答topic格式: $rrpc/txd/${ProductId}/${DeviceName}/${messageid}
        String topic  = String.format("$rrpc/txd/%s/%s/%s", mProductId, mDeviceName, processId);
        //TODO 通过replyMsg构建mqtt messge
        MqttMessage message = new MqttMessage();
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("test-key", "test-value"); // for test
            for (Map.Entry<String, String> entrys : replyMsg.entrySet()) {
                jsonObject.put(entrys.getKey(), entrys.getValue());
            }
        } catch (JSONException e) {
            TXLog.e(TAG, e, "pack json data failed!");
        }
        message.setQos(TXMqttConstants.QOS0);
        message.setPayload(jsonObject.toString().getBytes());
        return publish(topic, message ,userContext);
    }

主要是这段代码,这段测试代码是表示当前接口还不可用吗 还是基于什么考虑呢

archurcode commented 2 years ago

嗯,这块之前主要测试端侧和云端通路是否ok,这块我们会尽快调整,rrpc消息的回复动作交由业务层处理,调整好后再回复

archurcode commented 2 years ago

com.tencent.iot.hub.device.android.core.mqtt.TXMqttConnection#publishRRPCToCloud

    private Status publishRRPCToCloud(Object userContext, String processId, Map<String, String> replyMsg) {
        // 应答topic格式: $rrpc/txd/${ProductId}/${DeviceName}/${messageid}
        String topic  = String.format("$rrpc/txd/%s/%s/%s", mProductId, mDeviceName, processId);
        //TODO 通过replyMsg构建mqtt messge
        MqttMessage message = new MqttMessage();
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("test-key", "test-value"); // for test
            for (Map.Entry<String, String> entrys : replyMsg.entrySet()) {
                jsonObject.put(entrys.getKey(), entrys.getValue());
            }
        } catch (JSONException e) {
            TXLog.e(TAG, e, "pack json data failed!");
        }
        message.setQos(TXMqttConstants.QOS0);
        message.setPayload(jsonObject.toString().getBytes());
        return publish(topic, message ,userContext);
    }

主要是这段代码,这段测试代码是表示当前接口还不可用吗 还是基于什么考虑呢

这块已经修改了,可以在onMessageArrived回调里过滤rrpc消息,调用publishRRPCToCloud方法回复自定义内容

hendyzone commented 2 years ago

com.tencent.iot.hub.device.android.core.mqtt.TXMqttConnection#publishRRPCToCloud

    private Status publishRRPCToCloud(Object userContext, String processId, Map<String, String> replyMsg) {
        // 应答topic格式: $rrpc/txd/${ProductId}/${DeviceName}/${messageid}
        String topic  = String.format("$rrpc/txd/%s/%s/%s", mProductId, mDeviceName, processId);
        //TODO 通过replyMsg构建mqtt messge
        MqttMessage message = new MqttMessage();
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("test-key", "test-value"); // for test
            for (Map.Entry<String, String> entrys : replyMsg.entrySet()) {
                jsonObject.put(entrys.getKey(), entrys.getValue());
            }
        } catch (JSONException e) {
            TXLog.e(TAG, e, "pack json data failed!");
        }
        message.setQos(TXMqttConstants.QOS0);
        message.setPayload(jsonObject.toString().getBytes());
        return publish(topic, message ,userContext);
    }

主要是这段代码,这段测试代码是表示当前接口还不可用吗 还是基于什么考虑呢

这块已经修改了,可以在onMessageArrived回调里过滤rrpc消息,调用publishRRPCToCloud方法回复自定义内容

好的 感谢