From b2030052dda62a44875f751ff9fe061736988270 Mon Sep 17 00:00:00 2001
From: liuhaonan <31457034@qq.com>
Date: 星期三, 24 八月 2022 15:53:31 +0800
Subject: [PATCH] changes
---
ximon-admin/src/main/java/com/sandu/ximon/admin/manager/iot/rrpc/BaseInvokeSyncService.java | 61 +++++++++++++++++++-----------
1 files changed, 39 insertions(+), 22 deletions(-)
diff --git a/ximon-admin/src/main/java/com/sandu/ximon/admin/manager/iot/rrpc/BaseInvokeSyncService.java b/ximon-admin/src/main/java/com/sandu/ximon/admin/manager/iot/rrpc/BaseInvokeSyncService.java
index dcdb366..4b9aaf1 100644
--- a/ximon-admin/src/main/java/com/sandu/ximon/admin/manager/iot/rrpc/BaseInvokeSyncService.java
+++ b/ximon-admin/src/main/java/com/sandu/ximon/admin/manager/iot/rrpc/BaseInvokeSyncService.java
@@ -14,6 +14,7 @@
import com.sandu.ximon.admin.manager.iot.rrpc.topic.IBaseTopic;
import com.sandu.ximon.admin.manager.iot.rrpc.topic.ICustomizeTopic;
import com.sandu.ximon.admin.manager.iot.rrpc.util.FrameUtils;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import java.util.List;
@@ -23,6 +24,7 @@
* @author chenjiantian
* @date 2021/12/2 18:21
*/
+@Slf4j
public abstract class BaseInvokeSyncService implements IInvoke, IBaseTopic, ICustomizeTopic {
/**
@@ -33,10 +35,10 @@
* @param clz 鍐呴儴甯у搷搴斿疄浣撶被 濡傛灉涓嶆兂鑷繁瑙f瀽 鍙甫涓�
* @return 杩斿洖鐨勮В鐮佸抚瀹炰綋绫� 鍚屾椂鎶婂唴閮ㄥ抚瑙g爜涔嬪悗涔熸惡甯︿笂
*/
- public <T extends BaseResponseInnerFrame<T>> WrapResponseCommonFrame<T> sendRRPC(String deviceName, IRequestFrame iRequestFrame, Class<T> clz){
+ public <T extends BaseResponseInnerFrame<T>> WrapResponseCommonFrame<T> sendRRPC(String deviceName, IRequestFrame iRequestFrame, Class<T> clz) {
CommonFrame commonFrame = sendRRPC(deviceName, iRequestFrame);
if (commonFrame == null) {
- throw new BusinessException("rrpc璇锋眰澶辫触");
+ return null;
}
WrapResponseCommonFrame<T> responseCommonFrame = new WrapResponseCommonFrame<>();
BeanUtils.copyProperties(commonFrame, responseCommonFrame);
@@ -61,8 +63,7 @@
result = result.replace("\\", "");
Map map = JSON.parseObject(result, Map.class);
result = (String) map.get("msg");
- CommonFrame connectFrame = FrameUtils.transformMessageToFrame(result);
- return connectFrame;
+ return FrameUtils.transformMessageToFrame(result);
}
/**
@@ -151,7 +152,7 @@
return null;
}
- /**
+ /**
* 璋冪敤鑷畾涔塼opic
* https://help.aliyun.com/document_detail/69584.htm?spm=a2c4g.11186623.0.0.25b33982bSQSom#reference-snk-mrz-wdb
*
@@ -170,24 +171,40 @@
request.setIdentifier("rrpc");
request.setArgs(JSON.toJSONString(param));
+
// 鑾峰緱鏈嶅姟璋冪敤鍝嶅簲
- InvokeThingServiceResponse response = null;
- try {
- response = getClient().getAcsResponse(request);
- } catch (ClientException e) {
- e.printStackTrace();
+ return getAcsResponse(request, 1);
+ }
+
+ /**
+ * 鑾峰緱鏈嶅姟璋冪敤鍝嶅簲
+ *
+ * @param request
+ * @return
+ */
+ private InvokeThingServiceResponse.Data getAcsResponse(InvokeThingServiceRequest request, int time) {
+ if (time <= 3) {
+ InvokeThingServiceResponse response = null;
+ try {
+ response = getClient().getAcsResponse(request);
+ if (response == null) {
+ log.error("璋冪敤rrpc澶辫触锛屽搷搴斾负绌猴紒");
+ Thread.sleep(100);
+ return getAcsResponse(request, time + 1);
+ }
+ if (!response.getSuccess()) {
+ log.error("璋冪敤rrpc澶辫触锛�" + response.getErrorMessage());
+ Thread.sleep(100);
+ return getAcsResponse(request, time + 1);
+ } else {
+ // 鏈嶅姟璋冪敤鎴愬姛锛屼粎浠h〃鍙戦�佹湇鍔℃寚浠ょ殑鎴愬姛锛屼笉浠h〃鎵ц鏈嶅姟鏈韩鏄惁鎴愬姛
+ return response.getData();
+ }
+ } catch (Exception e) {
+ throw new BusinessException(e.getMessage());
+ }
+ } else {
+ throw new BusinessException("纭欢璇锋眰澶辫触锛岃妫�鏌ョ‖浠惰澶囷紒");
}
- if (response == null) {
- throw new BusinessException("璋冪敤rrpc澶辫触");
- }
- if (!response.getSuccess()) {
- throw new BusinessException("璋冪敤rrpc澶辫触锛�" + response.getErrorMessage());
- }
- // 鏈嶅姟璋冪敤鎴愬姛锛屼粎浠h〃鍙戦�佹湇鍔℃寚浠ょ殑鎴愬姛锛屼笉浠h〃鎵ц鏈嶅姟鏈韩鏄惁鎴愬姛
- if (response.getSuccess()) {
- // 浠呭悓姝ユ湇鍔℃湁result
- return response.getData();
- }
- return null;
}
}
--
Gitblit v1.9.3