package com.sandu.ximon.admin.manager.iot.rrpc.mainboard; import com.aliyuncs.DefaultAcsClient; import com.aliyuncs.profile.DefaultProfile; import com.aliyuncs.profile.IClientProfile; import com.sandu.ximon.admin.manager.iot.amqp.MqttMainBoardConfig; import com.sandu.ximon.admin.manager.iot.rrpc.BaseInvokeSyncService; /** * @author chenjiantian * @date 2021/12/3 11:31 * 主板rrpc通信实现类 */ public class MainBoardInvokeSyncService extends BaseInvokeSyncService { private static volatile DefaultAcsClient client = null; private final static String PRODUCT_KEY = "a1JsfPG4iKW"; @Override public String getProductKey() { return PRODUCT_KEY; } // @Override // public CommonFrame sendRRPC(String deviceName, IRequestFrame iRequestFrame) { // InvokeParam param = new InvokeParam(); // param.setOperate("1001"); // param.setFrame(iRequestFrame.getEncodeFrame()); // InvokeThingServiceResponse.Data data = invokeThing(deviceName, param); // if (data == null) { // return null; // } // String result = data.getResult(); // result = result.replace("\\", ""); // Map map = JSON.parseObject(result, Map.class); // result = (String) map.get("msg"); // CommonFrame connectFrame = FrameUtils.transformMessageToFrame(result); // return connectFrame; // } // // @Override // public > WrapResponseCommonFrame sendRRPC(String deviceName, IRequestFrame iRequestFrame, Class clz) { // CommonFrame commonFrame = sendRRPC(deviceName, iRequestFrame); // if (commonFrame == null) { // throw new BusinessException("rrpc请求失败"); // } // WrapResponseCommonFrame responseCommonFrame = new WrapResponseCommonFrame<>(); // BeanUtils.copyProperties(commonFrame, responseCommonFrame); // try { // responseCommonFrame.setResponseInnerFrame(clz.newInstance().transformFrame(responseCommonFrame.getPayload())); // } catch (InstantiationException | IllegalAccessException e) { // throw new BusinessException(String.format("找不到%s的构造函数", clz.getName())); // } // return responseCommonFrame; // } private static class SingletonClassInstance { private static final MainBoardInvokeSyncService INSTANCE = new MainBoardInvokeSyncService(); } protected MainBoardInvokeSyncService() { } public static MainBoardInvokeSyncService getInstance() { return SingletonClassInstance.INSTANCE; } @Override public DefaultAcsClient getClient() { if (client == null) { synchronized (MainBoardInvokeSyncService.class) { if (client == null) { IClientProfile profile = DefaultProfile.getProfile("cn-shanghai", MqttMainBoardConfig.ACCESS_KEY, MqttMainBoardConfig.ACCESS_SECRET); DefaultProfile.addEndpoint("cn-shanghai", "Iot", "iot.cn-shanghai.aliyuncs.com"); client = new DefaultAcsClient(profile); } } } return client; } }