From 3857e3a8753ac158238f461ef74107a572b510b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=AE=89=E5=90=9B?= <2746727141@qq.com> Date: Thu, 18 Apr 2024 21:38:49 +0800 Subject: [PATCH] =?UTF-8?q?feat=20commit=20=E7=BD=91=E5=85=B3=E8=B4=9F?= =?UTF-8?q?=E8=BD=BD=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/redis/service/RedisService.java | 61 +++++++++++----- .../zhilian/online/Timer/LoadObserver.java | 45 ++++++++++++ .../online/ZhiLianOnlineApplication.java | 33 ++++++++- .../online/constans/OnlineConstants.java | 25 +++++-- .../online/consumer/DeadQueueConsumer.java | 7 +- .../controller/OnlineGatherController.java | 32 --------- .../OnlineLoadCenterController.java | 8 +-- .../controller/OnlineVerifyController.java | 49 ------------- .../online/domain/model/GatewayNodeInfo.java | 35 +++++++++ .../online/domain/req/EcsCreateReq.java | 18 ++--- .../online/domain/req/EcsQueryReq.java | 2 +- .../online/load/abs/GatewayCacheAbs.java | 26 +++++++ .../load/cache/GatewayLoadNodeCache.java | 66 +++++++++++++++++ .../load/cache/GatewayLoadSeriesCache.java | 71 +++++++++++++++++++ .../online/load/cache/GatewayNodeCache.java | 68 ++++++++++++++++++ .../load/cache/GatewayNodeLoadInfoCache.java | 41 +++++++++++ .../load/cache/GatewayVehicleNodeCaChe.java | 56 +++++++++++++++ .../online/mapper/OnlineGatherMapper.java | 17 ----- .../service/OnlineLoadCenterService.java | 2 +- .../service/impl/OnlineGatherServiceImpl.java | 22 ------ .../impl/OnlineLoadCenterServiceImpl.java | 24 ++++--- .../online/uitls/AliyunOpenAPIUtils.java | 61 ++++++++++++++-- .../com/zhilian/online/uitls/MqttUtil.java | 68 ++++++++++++++++++ .../mapper/online/OnlineGatherMapper.xml | 7 -- 24 files changed, 658 insertions(+), 186 deletions(-) create mode 100644 zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/Timer/LoadObserver.java delete mode 100644 zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/controller/OnlineGatherController.java delete mode 100644 zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/controller/OnlineVerifyController.java create mode 100644 zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/domain/model/GatewayNodeInfo.java create mode 100644 zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/load/abs/GatewayCacheAbs.java create mode 100644 zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/load/cache/GatewayLoadNodeCache.java create mode 100644 zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/load/cache/GatewayLoadSeriesCache.java create mode 100644 zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/load/cache/GatewayNodeCache.java create mode 100644 zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/load/cache/GatewayNodeLoadInfoCache.java create mode 100644 zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/load/cache/GatewayVehicleNodeCaChe.java delete mode 100644 zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/mapper/OnlineGatherMapper.java delete mode 100644 zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/service/impl/OnlineGatherServiceImpl.java create mode 100644 zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/uitls/MqttUtil.java delete mode 100644 zhilian-modules/zhilian-online/src/main/resources/mapper/online/OnlineGatherMapper.xml diff --git a/zhilian-common/zhilian-common-redis/src/main/java/com/zhilian/common/redis/service/RedisService.java b/zhilian-common/zhilian-common-redis/src/main/java/com/zhilian/common/redis/service/RedisService.java index b00f85d..2981515 100644 --- a/zhilian-common/zhilian-common-redis/src/main/java/com/zhilian/common/redis/service/RedisService.java +++ b/zhilian-common/zhilian-common-redis/src/main/java/com/zhilian/common/redis/service/RedisService.java @@ -156,13 +156,13 @@ public class RedisService { /** * 缓存Set * - * @param key 缓存键值 + * @param key 缓存键值 * @param setValue 缓存的数据 * @return 缓存数据的对象 */ public BoundSetOperations setCacheSet(final String key, final T setValue) { BoundSetOperations setOperation = redisTemplate.boundSetOps(key); - setOperation.add(setValue); + setOperation.add(setValue); return setOperation; } @@ -272,8 +272,6 @@ public class RedisService { } - - /** * 获取Zset集合大小 * @@ -310,6 +308,7 @@ public class RedisService { /** * 范围查询集合携带分数 + * * @param zkey * @param start * @param end @@ -329,46 +328,50 @@ public class RedisService { /** * 修改对应键值分数,delta为正数则增加,为负数则减少 + * * @param zkey * @param value * @param delta * @param */ - public Double incrementScore(final String zkey, final T value, final Double delta){ - return redisTemplate.opsForZSet().incrementScore(zkey,value,delta); + public Double incrementScore(final String zkey, final T value, final Double delta) { + return redisTemplate.opsForZSet().incrementScore(zkey, value, delta); } /** * 删除元素 + * * @param zkey * @param values - * @return * @param + * @return */ - public Long removeCacheZsetBatch(final String zkey,final T... values){ - return redisTemplate.opsForZSet().remove(zkey,values); + public Long removeCacheZsetBatch(final String zkey, final T... values) { + return redisTemplate.opsForZSet().remove(zkey, values); } /** * 排序并限制结果集大小,按降序返回有序集合的部分元素,支持指定索引范围。 + * * @param zkey * @param start * @param end * @return */ - public Set reverseRange(final String zkey,final Long start,final Long end){ - return redisTemplate.opsForZSet().reverseRange(zkey,start,end); + public Set reverseRange(final String zkey, final Long start, final Long end) { + return redisTemplate.opsForZSet().reverseRange(zkey, start, end); } /** * 按分数范围查询 + * * @param zkey * @param min * @param max * @return */ - public Set rangeByScore(final String zkey,final Double min,final Double max){ - return redisTemplate.opsForZSet().rangeByScore(zkey,min,max); + public Set rangeByScore(final String zkey, final Double min, final Double max) { + return redisTemplate.opsForZSet().rangeByScore(zkey, min, max); } /** @@ -377,7 +380,7 @@ public class RedisService { * @param zkey * @return */ - public ZSetOperations.TypedTuple getCacheZsetMin(final String zkey){ + public ZSetOperations.TypedTuple getCacheZsetMin(final String zkey) { ZSetOperations.TypedTuple typedTuple = redisTemplate.opsForZSet().popMin(zkey); return typedTuple; } @@ -393,13 +396,37 @@ public class RedisService { return redisTemplate.keys(pattern); } - public void deleteCacheSet(String key) { + public void deleteCacheSet(final String key) { SetOperations setOperations = redisTemplate.opsForSet(); setOperations.remove(key); } - public void deleteCacheSetValue(String key, T value) { + public void deleteCacheSetValue(final String key, final T value) { SetOperations setOperations = redisTemplate.opsForSet(); - setOperations.remove(key,value); + setOperations.remove(key, value); + } + + /** + * @description: 根据下标获取List中value + * @author: LiYuan + * @param: key ,index 下标 + * @return: value + **/ + public T getcacheListValue(final String key, final Long index) { + ListOperations listOperations = redisTemplate.opsForList(); + + return (T) listOperations.index(key, index); + } + + + /** + * @description: 增加String类型中缓存值 + * @author: LiYuan + * @param: key,number + * @return: Long 增加后的值 + **/ + public Long increment(final String key,final Long number) { + ValueOperations valueOperations = redisTemplate.opsForValue(); + return valueOperations.increment(key,number); } } diff --git a/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/Timer/LoadObserver.java b/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/Timer/LoadObserver.java new file mode 100644 index 0000000..708e3dc --- /dev/null +++ b/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/Timer/LoadObserver.java @@ -0,0 +1,45 @@ +package com.zhilian.online.Timer; + +import com.zhilian.online.uitls.AliyunOpenAPIUtils; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +/** + * @BelongsProject: smart-cloud-server + * @BelongsPackage: com.zhilian.online.Timer + * @Author: LiYuan + * @CreateTime: 2024-04-17 21:53 + * @Description: 收集节点监视者 + * @Version: 1.0 + */ +@Component +@Slf4j +public class LoadObserver { + + /** + * 阿里云api接口类 + */ + @Autowired + private AliyunOpenAPIUtils aliyunOpenAPIUtils; + + /** + * 监视负载量是否需要扩容 + */ + @Scheduled(cron = "0/10 * * * * ?") + public void addInstance(){ + + + + } + + /** + * 监视负载量是否需要缩容 + */ + @Scheduled(cron = "0/10 * * * * ?") + public void ReduceInstance(){ + + } + +} diff --git a/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/ZhiLianOnlineApplication.java b/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/ZhiLianOnlineApplication.java index 032d799..63a7066 100644 --- a/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/ZhiLianOnlineApplication.java +++ b/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/ZhiLianOnlineApplication.java @@ -4,6 +4,7 @@ import com.zhilian.common.security.annotation.EnableCustomConfig; import com.zhilian.common.security.annotation.EnableMyFeignClients; import com.zhilian.common.swagger.annotation.EnableCustomSwagger2; import com.zhilian.online.controller.OnlineLoadCenterController; +import com.zhilian.online.domain.req.EcsCreateReq; import com.zhilian.online.uitls.AliyunOpenAPIUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -11,6 +12,7 @@ import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import com.aliyun.ecs20140526.models.RunInstancesRequest; /** * @version: @@ -23,16 +25,41 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @EnableMyFeignClients @SpringBootApplication @Slf4j -public class ZhiLianOnlineApplication implements ApplicationRunner{ +public class ZhiLianOnlineApplication implements ApplicationRunner { @Autowired private AliyunOpenAPIUtils aliyunOpenAPIUtils; + public static void main(String[] args) { - SpringApplication.run(ZhiLianOnlineApplication.class,args); + SpringApplication.run(ZhiLianOnlineApplication.class, args); } @Override public void run(ApplicationArguments args) throws Exception { log.info("项目启动,调用创建实例方法"); -// aliyunOpenAPIUtils.createInstance(); + RunInstancesRequest.RunInstancesRequestSystemDisk systemDisk = new RunInstancesRequest.RunInstancesRequestSystemDisk(); + systemDisk = systemDisk.setSize("20").setCategory("cloud_efficiency"); + EcsCreateReq ecs = EcsCreateReq.builder() + .regionId("cn-zhangjiakou") + .imageId("m-8vbfx0e48cekro0f13bx") + .instanceType("ecs.t6-c1m1.large") + .securityGroupId("sg-8vb49jd1c1lsa3akwo02") + .vSwitchId("vsw-8vb0krtyfdmb27nhcmzc2") + .instanceName("gather-node") + .internetMaxBandwidthIn(80) + .internetMaxBandwidthOut(10) + .uniqueSuffix(true) + .password("142730.Ly") + .zoneId("cn-zhangjiakou-c") + .internetChargeType("PayByTraffic") + .systemDiskSize("20") + .systemDickCategory("cloud_efficiency") + .amount(1) + .minAmount(1) + .periodUnit("Week") + .period(1) + .instanceChargeType("PostPaid") + .privateIpAddress("10.10.27.1") + .build(); + aliyunOpenAPIUtils.createInstance(ecs); } } diff --git a/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/constans/OnlineConstants.java b/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/constans/OnlineConstants.java index 9de409f..7105cd3 100644 --- a/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/constans/OnlineConstants.java +++ b/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/constans/OnlineConstants.java @@ -16,7 +16,7 @@ public class OnlineConstants { /** * 申请注册令牌缓存前缀 */ - public static final String ONLINE_TOKEN_PREFIX = "online_token:"; + public static final String NODE_TOKEN_PREFIX = "node_token:"; /** * 申请令牌过期时间 @@ -26,12 +26,27 @@ public class OnlineConstants { /** * 节点负载前缀 */ - public static final String GATHER_LOAD_CONTROL = "gather_info_control"; + public static final String GATHER_LOAD_PREFIX = "gather:load:"; /** - * 节点负载信息 + * 在线节点前缀 */ - public static final String ONLINE_VEHICLE = "online_vehicle:"; + public static final String ONLINE_GATHER_PREFIX = "online_vehicle:"; + + /** + * http请求前缀 + */ + public static final String HTTP_PREFIX = "http://"; + + /** + * https请求前缀 + */ + public static final String HTTPS_PREFIX = "https://"; + + /** + * fluxMQ请求地址 + */ + public static final String FLUXMQ_INFO_URL = ":8080/public/cluster"; + - } diff --git a/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/consumer/DeadQueueConsumer.java b/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/consumer/DeadQueueConsumer.java index 07c1803..7314c72 100644 --- a/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/consumer/DeadQueueConsumer.java +++ b/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/consumer/DeadQueueConsumer.java @@ -1,12 +1,9 @@ package com.zhilian.online.consumer; -import com.alibaba.fastjson.JSON; import com.zhilian.common.core.constant.Constants; import com.zhilian.common.redis.service.RedisService; -import com.zhilian.online.config.RabbitConfig; import com.zhilian.online.constans.OnlineConstants; import lombok.extern.slf4j.Slf4j; -import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -54,8 +51,8 @@ public class DeadQueueConsumer { if (Constants.FAIL == responseCode){ log.error("节点{}上线失败",gatherMsg); //上线失败需要将该节点的负载均衡缓存删除 - if (redisService.hasKey(OnlineConstants.ONLINE_TOKEN_PREFIX + "")){ - redisService.removeCacheZsetBatch(OnlineConstants.ONLINE_TOKEN_PREFIX + ""); + if (redisService.hasKey(OnlineConstants.NODE_TOKEN_PREFIX + "")){ + redisService.removeCacheZsetBatch(OnlineConstants.NODE_TOKEN_PREFIX + ""); } } } catch (Exception e) { diff --git a/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/controller/OnlineGatherController.java b/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/controller/OnlineGatherController.java deleted file mode 100644 index 966ca20..0000000 --- a/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/controller/OnlineGatherController.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.zhilian.online.controller; - -import com.zhilian.common.core.domain.Result; - -import com.zhilian.online.service.OnlineGatherService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -/** - * @version: - * @Author: LiYuan - * @description: 车辆收集节点控制层 - * @date: 2024/3/29 20:46 - */ -@RestController -@RequestMapping("/gather") -public class OnlineGatherController { - - /** - * 车辆收集节点 - */ - @Autowired - private OnlineGatherService onlineGatherService; - - - - - -} diff --git a/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/controller/OnlineLoadCenterController.java b/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/controller/OnlineLoadCenterController.java index 461d641..610eedb 100644 --- a/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/controller/OnlineLoadCenterController.java +++ b/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/controller/OnlineLoadCenterController.java @@ -40,14 +40,14 @@ public class OnlineLoadCenterController extends BaseController { /** * @description: 节点申请注解令牌接口, 仅限内网访问 - * @author: LiY + * @author: LiYuan * @param: vehicle * @return: Result **/ @GetMapping("/applyForReg") - public Result applyForReg() { - log.info("申请注册令牌"); - return onlineLoadCenterService.applyForReg(); + public Result applyForReg(String clusterId) { + log.info("节点{}申请注册令牌",clusterId); + return onlineLoadCenterService.applyForReg(clusterId); } diff --git a/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/controller/OnlineVerifyController.java b/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/controller/OnlineVerifyController.java deleted file mode 100644 index 3e53dd6..0000000 --- a/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/controller/OnlineVerifyController.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.zhilian.online.controller;/** - * @version: - * @Author: LiYuan - * @description: - * @date: 2024/3/30 11:18 - */ - -import com.zhilian.common.core.domain.Result; -import com.zhilian.online.domain.model.MqttServerModel; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -/** - * @BelongsProject: smart-cloud-server - * @BelongsPackage: com.zhilian.online.controller - * @Author: LiYuan - * @CreateTime: 2024-03-30 11:18 - * @Description: 新增车辆上线验证控制器 - * @Version: 1.0 - */ -@RestController -@RequestMapping("/verify") -public class OnlineVerifyController { - - /** - * 读取配置文件中的mqtt服务地址 - */ - @Value("${mqtt.server.broker}") - private String broker; - - /** - * 读取配置文件中的订阅主题 - */ - @Value("${mqtt.server.topic}") - private String topic; - - @PostMapping("/vehicleConnection") - public Result vehicleConnection() { - return Result.success( - MqttServerModel.builder() - .broker(broker) - .topic(topic) - .build() - ); - } - -} diff --git a/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/domain/model/GatewayNodeInfo.java b/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/domain/model/GatewayNodeInfo.java new file mode 100644 index 0000000..a1e7460 --- /dev/null +++ b/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/domain/model/GatewayNodeInfo.java @@ -0,0 +1,35 @@ +package com.zhilian.online.domain.model; + +import lombok.*; + +/** + * @BelongsProject: smart-cloud-server + * @BelongsPackage: com.zhilian.online.domain.model + * @Author: LiYuan + * @CreateTime: 2024-04-18 19:47 + * @Description: 收集节点信息 + * @Version: 1.0 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@ToString +@Builder +public class GatewayNodeInfo { + + /** + * 节点id + */ + private String nodeId; + + /** + * 公网IP + */ + private String publicIpAddress; + + /** + * 内网IP + */ + private String privateIpAddress; + +} diff --git a/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/domain/req/EcsCreateReq.java b/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/domain/req/EcsCreateReq.java index 20c0b3c..f7f83c4 100644 --- a/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/domain/req/EcsCreateReq.java +++ b/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/domain/req/EcsCreateReq.java @@ -36,12 +36,12 @@ public class EcsCreateReq { /** * 镜像ID */ - private String ImageId; + private String imageId; /** * 实例规格 */ - private String InstanceType; + private String instanceType; /** * 安全组ID @@ -85,37 +85,37 @@ public class EcsCreateReq { private String zoneId; /** - * + * 网络计费类型 */ private String internetChargeType; /** - * + * 购买数量 */ private Integer amount; /** - * + * 最小购买数量 */ private Integer minAmount; /** - * + * 购买时长单位 */ private String periodUnit; /** - * + * 购买时长 */ private Integer period; /** - * + * 实例付费类型 */ private String instanceChargeType; /** - * + * 私网IP */ private String privateIpAddress; diff --git a/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/domain/req/EcsQueryReq.java b/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/domain/req/EcsQueryReq.java index e66714b..f405914 100644 --- a/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/domain/req/EcsQueryReq.java +++ b/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/domain/req/EcsQueryReq.java @@ -9,7 +9,7 @@ import javax.validation.constraints.NotBlank; * @BelongsPackage: com.zhilian.online.domain.req * @Author: LiYuan * @CreateTime: 2024-04-12 15:37 - * @Description: 调用阿里云openAPI查询实例请求实体类 + * @Description: 阿里云openAPI查询实例请求 * @Version: 1.0 */ @Data diff --git a/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/load/abs/GatewayCacheAbs.java b/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/load/abs/GatewayCacheAbs.java new file mode 100644 index 0000000..97c9b52 --- /dev/null +++ b/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/load/abs/GatewayCacheAbs.java @@ -0,0 +1,26 @@ +package com.zhilian.online.load.abs; + +import com.zhilian.common.redis.service.RedisService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * @BelongsProject: smart-cloud-server + * @BelongsPackage: com.zhilian.online.load.abs + * @Author: LiYuan + * @CreateTime: 2024-04-18 19:09 + * @Description: 网关负载均衡缓存抽象类 + * @Version: 1.0 + */ +public abstract class GatewayCacheAbs { + + @Autowired + public RedisService redisService; + + public abstract String getPre(); + + public String encode(K key) { + return getPre() + key; + } + +} diff --git a/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/load/cache/GatewayLoadNodeCache.java b/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/load/cache/GatewayLoadNodeCache.java new file mode 100644 index 0000000..6f736a8 --- /dev/null +++ b/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/load/cache/GatewayLoadNodeCache.java @@ -0,0 +1,66 @@ +package com.zhilian.online.load.cache; + +import com.zhilian.common.redis.service.RedisService; +import com.zhilian.online.load.abs.GatewayCacheAbs; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.List; + +/** + * @BelongsProject: smart-cloud-server + * @BelongsPackage: com.zhilian.online.load.cache + * @Author: LiYuan + * @CreateTime: 2024-04-18 19:11 + * @Description: 网关负载均衡节点缓存 + * @Version: 1.0 + */ +@Component +public class GatewayLoadNodeCache extends GatewayCacheAbs { + + + + private final static String gatewayLoadNodeKey = "node"; + + @Override + public String getPre() { + return "gateway:load:"; + } + + /** + * @description: 存负载节点 + * @author: LiYuan + * @param: nodeList + * @return: void + **/ + public void put(List nodeList) { + redisService.deleteObject(encode(gatewayLoadNodeKey)); + redisService.setCacheList(encode(gatewayLoadNodeKey), nodeList); + } + + /** + * @description: 获取所有负载节点 + * @author: LiYuan + * @param: null + * @return: List + **/ + public List get() { + return redisService.getCacheList(encode(gatewayLoadNodeKey)); + } + + + /** + * @description: 通过下标获取节点 + * @author: LiYuan + * @param: index 下标 + * @return: String node 节点 + **/ + public String getByIndex(Long index){ + if (null == index || index > 100){ + throw new RuntimeException("下标违法,不在[0-100]内"); + } + return redisService.getcacheListValue(encode(gatewayLoadNodeKey),index); + } + + +} diff --git a/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/load/cache/GatewayLoadSeriesCache.java b/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/load/cache/GatewayLoadSeriesCache.java new file mode 100644 index 0000000..6439472 --- /dev/null +++ b/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/load/cache/GatewayLoadSeriesCache.java @@ -0,0 +1,71 @@ +package com.zhilian.online.load.cache; + +import com.zhilian.online.load.abs.GatewayCacheAbs; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; + +/** + * @BelongsProject: smart-cloud-server + * @BelongsPackage: com.zhilian.online.load.cache + * @Author: LiYuan + * @CreateTime: 2024-04-18 19:34 + * @Description: 网关负载自增序列 + * @Version: 1.0 + */ +@Component +public class GatewayLoadSeriesCache extends GatewayCacheAbs { + + private final static String gatewayLoadSeriesKey = "series"; + + + @Override + public String getPre() { + return "gateway:load:"; + } + + /** + * @description: 创建Bean后初始化自增序列 + * @author: LiYuan + * @param: + * @return: + **/ + @PostConstruct + public void init() { + redisService.setCacheObject(encode(gatewayLoadSeriesKey), 0); + } + + + /** + * @description: 获取自增序列的值 + * @author: LiYuan + * @param: + * @return: Long + **/ + public Long incrementAndGet() { + return redisService.increment(encode(gatewayLoadSeriesKey), 1L); + } + + + /** + * @description: 获取当前序列的值 + * @author: LiYuan + * @param: + * @return: + **/ + public Long get() { + return redisService.getCacheObject(encode(gatewayLoadSeriesKey)); + } + + /** + * @description: 重置序列中的值 + * @author: LiYuan + * @param: + * @return: + **/ + public void reset() { + this.init(); + } + + +} diff --git a/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/load/cache/GatewayNodeCache.java b/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/load/cache/GatewayNodeCache.java new file mode 100644 index 0000000..b1915c5 --- /dev/null +++ b/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/load/cache/GatewayNodeCache.java @@ -0,0 +1,68 @@ +package com.zhilian.online.load.cache; + +import com.zhilian.online.domain.model.GatewayNodeInfo; +import com.zhilian.online.load.abs.GatewayCacheAbs; +import org.springframework.stereotype.Component; + +import java.util.List; + +/** + * @BelongsProject: smart-cloud-server + * @BelongsPackage: com.zhilian.online.load.cache + * @Author: LiYuan + * @CreateTime: 2024-04-18 19:44 + * @Description: 网关负载中心节点数据缓存 String key + nodeInfo 对象 + * @Version: 1.0 + */ +@Component +public class GatewayNodeCache extends GatewayCacheAbs { + + + @Override + public String getPre() { + return "gateway:node:info"; + } + + /** + * @description: 增加节点数据 + * @author: LiYuan + * @param: GatewayNodeInfo 节点数据 + * @return: + **/ + public void put(GatewayNodeInfo gatewayNodeInfo){ + redisService.setCacheObject(encode(gatewayNodeInfo.getNodeId()),gatewayNodeInfo); + } + + /** + * @description: 获取节点缓存数据 + * @author: LiYuan + * @param: nodeId 节点Id + * @return: + **/ + public GatewayNodeInfo get(String nodeId){ + return redisService.getCacheObject(encode(nodeId)); + } + + + /** + * @description: 获取所有节点数据 + * @author: LiYuan + * @param: + * @return: + **/ + public List get(){ + return redisService.getCacheObject(encode(getPre())); + } + + /** + * @description: 删除网关节点 + * @author: LiYuan + * @param: + * @return: + **/ + public void remove(String nodeId){ + redisService.deleteObject(encode(nodeId)); + } + + +} diff --git a/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/load/cache/GatewayNodeLoadInfoCache.java b/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/load/cache/GatewayNodeLoadInfoCache.java new file mode 100644 index 0000000..9b3c6b0 --- /dev/null +++ b/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/load/cache/GatewayNodeLoadInfoCache.java @@ -0,0 +1,41 @@ +package com.zhilian.online.load.cache; + +import com.zhilian.online.load.abs.GatewayCacheAbs; +import org.springframework.stereotype.Component; + +import java.util.Map; + +/** + * @BelongsProject: smart-cloud-server + * @BelongsPackage: com.zhilian.online.load.cache + * @Author: LiYuan + * @CreateTime: 2024-04-18 20:03 + * @Description: 收集节点负载量数据 Zset : 车辆连接数 + * @Version: 1.0 + */ +@Component +public class GatewayNodeLoadInfoCache extends GatewayCacheAbs { + + private final static String gatewayZset = "node-connects:"; + + @Override + public String getPre() { + return "gateway:Zset:"; + } + + + /** + * @description: 获取所有Zset集合 + * @author: LiYuan + * @param: + * @return: + **/ + public Map get(){ + return redisService.getCacheObject(encode(gatewayZset)); + } + + + + + +} diff --git a/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/load/cache/GatewayVehicleNodeCaChe.java b/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/load/cache/GatewayVehicleNodeCaChe.java new file mode 100644 index 0000000..5faf584 --- /dev/null +++ b/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/load/cache/GatewayVehicleNodeCaChe.java @@ -0,0 +1,56 @@ +package com.zhilian.online.load.cache; + +import com.zhilian.online.load.abs.GatewayCacheAbs; +import org.springframework.stereotype.Component; + +/** + * @BelongsProject: smart-cloud-server + * @BelongsPackage: com.zhilian.online.load.cache + * @Author: LiYuan + * @CreateTime: 2024-04-18 19:58 + * @Description: 车辆上线数据 + * @Version: 1.0 + */ +@Component +public class GatewayVehicleNodeCaChe extends GatewayCacheAbs { + + private final static String gatewayCarBusinessKey = "business:"; + + @Override + public String getPre() { + return "gateway:car:"; + } + + /** + * @description: 存放车辆数据 + * @author: LiYuan + * @param: String vin, String nodeId + * @return: + **/ + public void put(String vin, String nodeId) { + redisService.setCacheObject(encode(gatewayCarBusinessKey) + vin,nodeId); + } + + + /** + * @description:删除车辆数据 + * @author: LiYuan + * @param: String vin + * @return: + **/ + public void remove(String vin){ + redisService.deleteObject(encode(gatewayCarBusinessKey) + vin); + } + + /** + * @description: 获取车辆连接数据 + * @author: LiYuan + * @param: String vin + * @return: + **/ + public String get(String vin){ + return redisService.getCacheObject(encode(gatewayCarBusinessKey) + vin); + } + + +} diff --git a/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/mapper/OnlineGatherMapper.java b/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/mapper/OnlineGatherMapper.java deleted file mode 100644 index d7e5e62..0000000 --- a/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/mapper/OnlineGatherMapper.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.zhilian.online.mapper; - -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import org.apache.ibatis.annotations.Mapper; - -/** - * @version: - * @Author: LiYuan - * @description: 车辆收集节点数据层 - * @date: 2024/3/29 20:48 - */ -@Mapper -public interface OnlineGatherMapper{ - - - -} diff --git a/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/service/OnlineLoadCenterService.java b/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/service/OnlineLoadCenterService.java index dc0cb06..385fa12 100644 --- a/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/service/OnlineLoadCenterService.java +++ b/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/service/OnlineLoadCenterService.java @@ -17,7 +17,7 @@ public interface OnlineLoadCenterService{ * @param: vehicle * @return: Result **/ - Result applyForReg(); + Result applyForReg(String clusterId); /** * @description: 车辆使用申请的一次性账户连接收集节点 diff --git a/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/service/impl/OnlineGatherServiceImpl.java b/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/service/impl/OnlineGatherServiceImpl.java deleted file mode 100644 index 6f2bd7f..0000000 --- a/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/service/impl/OnlineGatherServiceImpl.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.zhilian.online.service.impl; - -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.zhilian.common.core.domain.Result; -import com.zhilian.online.mapper.OnlineGatherMapper; -import com.zhilian.online.service.OnlineGatherService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -/** - * @version: - * @Author: LiYuan - * @description: 车辆收集节点服务层 - * @date: 2024/3/29 20:48 - */ -@Service -public class OnlineGatherServiceImpl implements OnlineGatherService { - - @Autowired - private OnlineGatherMapper onlineGatherMapper; - -} diff --git a/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/service/impl/OnlineLoadCenterServiceImpl.java b/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/service/impl/OnlineLoadCenterServiceImpl.java index 1af6585..8a98d59 100644 --- a/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/service/impl/OnlineLoadCenterServiceImpl.java +++ b/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/service/impl/OnlineLoadCenterServiceImpl.java @@ -9,6 +9,7 @@ import com.zhilian.online.constans.OnlineConstants; import com.zhilian.online.domain.ApifoxModel; import com.zhilian.online.mapper.OnlineLoadCenterMapper; import com.zhilian.online.service.OnlineLoadCenterService; +import com.zhilian.online.uitls.MqttUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Autowired; @@ -47,6 +48,12 @@ public class OnlineLoadCenterServiceImpl implements OnlineLoadCenterService{ @Autowired private RabbitTemplate rabbitTemplate; + /** + * MQTT服务 + */ + @Autowired + private MqttUtil mqttUtil; + /** * @description: 车辆申请注解令牌接口, 仅限内网访问 * @author: LiYuan @@ -54,13 +61,13 @@ public class OnlineLoadCenterServiceImpl implements OnlineLoadCenterService{ * @return: Result **/ @Override - public Result applyForReg() { + public Result applyForReg(String clusterId) { //生成一次性令牌 String token = IdUtils.fastSimpleUUID(); //将令牌信息缓存到Redis中 - redisService.setCacheObject(OnlineConstants.ONLINE_TOKEN_PREFIX + token,token, OnlineConstants.ONLINE_TOKEN_EXPIRE, TimeUnit.SECONDS); + redisService.setCacheObject(OnlineConstants.NODE_TOKEN_PREFIX + clusterId,token, OnlineConstants.ONLINE_TOKEN_EXPIRE, TimeUnit.SECONDS); //将令牌信息返回客户端 return Result.success(token); @@ -76,16 +83,17 @@ public class OnlineLoadCenterServiceImpl implements OnlineLoadCenterService{ @Override public Result regGather(ApifoxModel apifoxModel) { //判断登录令牌是否过期,一致 - if (!redisService.hasKey(OnlineConstants.ONLINE_TOKEN_PREFIX + apifoxModel.getToken())) { + if (!redisService.hasKey(OnlineConstants.NODE_TOKEN_PREFIX + apifoxModel.getClusterId())) { return Result.error("令牌已过期"); } - String token = redisService.getCacheObject(OnlineConstants.ONLINE_TOKEN_PREFIX + apifoxModel.getToken()); + String token = redisService.getCacheObject(OnlineConstants.NODE_TOKEN_PREFIX + apifoxModel.getClusterId()); if (!token.equals(apifoxModel.getToken())){ return Result.error("令牌错误"); } - //为该节点创建负载均衡缓存 - redisService.setCacheZsetValue(OnlineConstants.GATHER_LOAD_CONTROL + apifoxModel.getClusterId(), JSON.toJSONString(apifoxModel), 0.0); + //为该节点创建Zset负载均衡缓存,将该节点加入List在线节点缓存 + redisService.setCacheZsetValue(OnlineConstants.GATHER_LOAD_PREFIX, apifoxModel.getClusterId(), 0.0); + //向RabbitMQ||RocketMQ发送30s延迟消息,确保后续节点上线 rabbitTemplate.convertAndSend(RabbitConfig.DELAY_EXCHANGE_NAME, RabbitConfig.DELAY_ROUTING_KEY, JSON.toJSONString(apifoxModel)); @@ -110,10 +118,10 @@ public class OnlineLoadCenterServiceImpl implements OnlineLoadCenterService{ throw new RuntimeException("车辆未登记"); } //获取负载最少的车辆进行链接 - ZSetOperations.TypedTuple cacheZsetMin = redisService.getCacheZsetMin(OnlineConstants.GATHER_LOAD_CONTROL); + ZSetOperations.TypedTuple cacheZsetMin = redisService.getCacheZsetMin(OnlineConstants.GATHER_LOAD_PREFIX); //存放节点车辆信息 - redisService.setCacheObject(OnlineConstants.ONLINE_VEHICLE+vin,1); + redisService.setCacheObject(OnlineConstants.GATHER_LOAD_PREFIX+vin,1); //发送延迟队列确定车辆上线 rabbitTemplate.convertAndSend(RabbitConfig.DELAY_EXCHANGE_FOR_CAR, RabbitConfig.DELAY_ROUTING_FOR_CAR,vin); diff --git a/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/uitls/AliyunOpenAPIUtils.java b/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/uitls/AliyunOpenAPIUtils.java index 34d1cb6..90a0820 100644 --- a/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/uitls/AliyunOpenAPIUtils.java +++ b/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/uitls/AliyunOpenAPIUtils.java @@ -3,12 +3,14 @@ package com.zhilian.online.uitls; import com.aliyun.ecs20140526.models.*; import com.aliyun.tea.TeaException; import com.aliyun.teautil.models.RuntimeOptions; +import com.zhilian.common.core.domain.Result; import com.zhilian.online.domain.EcsInstance; import com.zhilian.online.domain.req.EcsCreateReq; import com.zhilian.online.domain.req.EcsQueryReq; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.springframework.validation.annotation.Validated; import com.aliyun.ecs20140526.Client; @@ -35,6 +37,9 @@ public class AliyunOpenAPIUtils { @Qualifier(value = "AliyunClient") private Client aliyunClient; + @Value("aliyun.ecs.region-id") + private String regionId; + /** * 查询实例方法 @@ -76,20 +81,25 @@ public class AliyunOpenAPIUtils { * @param: * @return: void **/ - public void createInstance(EcsCreateReq ecsCreateReq) { + public List createInstance(EcsCreateReq ecsCreateReq) { //创建实例请求 RunInstancesRequest runInstancesRequest = makeRunInstancesRequest(ecsCreateReq); RuntimeOptions runtime = new RuntimeOptions(); + + List instanceIds = new ArrayList<>(); + try { // 复制代码运行请自行打印 API 的返回值 RunInstancesResponse res = aliyunClient.runInstancesWithOptions(runInstancesRequest, runtime); //打印执行结果 RunInstancesResponseBody body = res.getBody(); + instanceIds = body.getInstanceIdSets().getInstanceIdSet(); log.info("执行结果:[{}],请求ID:[{}],创建实例ID:[{}]", 200 == res.getStatusCode() ? "创建成功" : "创建失败", - body.getRequestId(), body.getInstanceIdSets().getInstanceIdSet()); + body.getRequestId(), instanceIds); + } catch (TeaException error) { log.error("code:[{}],message:[{}],data:[{}]", error.getCode(), error.getMessage(), error.getData()); @@ -98,6 +108,38 @@ public class AliyunOpenAPIUtils { log.error("code:[{}],message:[{}],data:[{}]", error.getCode(), error.getMessage(), error.getData()); } + + return instanceIds; + + } + + public Result deleteInstance(String instanceId) { + Result result = new Result<>(); + DeleteInstancesRequest deleteInstancesRequest = new DeleteInstancesRequest() + .setRegionId(regionId) + .setDryRun(false) + .setForce(true) + .setTerminateSubscription(false) + .setInstanceId(java.util.Arrays.asList( + instanceId + )); + com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions(); + try { + // 复制代码运行请自行打印 API 的返回值 + DeleteInstancesResponse deleteInstancesResponse = aliyunClient.deleteInstancesWithOptions(deleteInstancesRequest, runtime); + Integer statusCode = deleteInstancesResponse.getStatusCode(); + DeleteInstancesResponseBody body = deleteInstancesResponse.getBody(); + log.info(200 == statusCode ? "删除成功" : "删除失败"); + result.setCode(statusCode); + result.setData(body); + result.setMsg(200 == statusCode ? "删除成功" : "删除失败"); + } catch (TeaException error) { + log.error("code:[{}],message:[{}],data:[{}]", error.getCode(), error.getMessage(), error.getData()); + } catch (Exception _error) { + TeaException error = new TeaException(_error.getMessage(), _error); + log.error("code:[{}],message:[{}],data:[{}]", error.getCode(), error.getMessage(), error.getData()); + } + return result; } @@ -109,7 +151,7 @@ public class AliyunOpenAPIUtils { **/ public DescribeInstancesRequest setQueryReq(EcsQueryReq ecsQueryReq) { return new DescribeInstancesRequest() - .setRegionId(ecsQueryReq.getRegionId()) + .setRegionId(regionId) .setInstanceName(ecsQueryReq.getInstanceName()) .setPageNumber(ecsQueryReq.getPageNumber()) .setPageSize(ecsQueryReq.getPageSize()) @@ -141,7 +183,7 @@ public class AliyunOpenAPIUtils { EcsInstance ecsInstance = EcsInstance.builder() .instanceId(item.getInstanceId()) .instanceName(item.getInstanceName()) - .regionId(item.getRegionId()) + .regionId(regionId) .status(item.getStatus()) .instanceType(item.getInstanceType()) .cpu(item.getCpu()) @@ -165,14 +207,21 @@ public class AliyunOpenAPIUtils { return ecsInstances; } - public RunInstancesRequest makeRunInstancesRequest(EcsCreateReq ecsCreateReq){ + /** + * 构建阿里云创建实例请求 + * + * @param: ecsCreateReq + * @return: RunInstancesRequest + */ + public RunInstancesRequest makeRunInstancesRequest(EcsCreateReq ecsCreateReq) { + //构建磁盘配置 RunInstancesRequest.RunInstancesRequestSystemDisk systemDisk = new RunInstancesRequest.RunInstancesRequestSystemDisk() .setSize(ecsCreateReq.getSystemDiskSize()) .setCategory(ecsCreateReq.getSystemDickCategory()); //构建创建实例请求 RunInstancesRequest runInstancesRequest = new RunInstancesRequest() - .setRegionId(ecsCreateReq.getRegionId()) + .setRegionId(regionId) .setImageId(ecsCreateReq.getImageId()) .setInstanceType(ecsCreateReq.getInstanceType()) .setSecurityGroupId(ecsCreateReq.getSecurityGroupId()) diff --git a/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/uitls/MqttUtil.java b/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/uitls/MqttUtil.java new file mode 100644 index 0000000..dfc8992 --- /dev/null +++ b/zhilian-modules/zhilian-online/src/main/java/com/zhilian/online/uitls/MqttUtil.java @@ -0,0 +1,68 @@ +package com.zhilian.online.uitls; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.zhilian.online.constans.OnlineConstants; +import lombok.extern.slf4j.Slf4j; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import org.springframework.stereotype.Component; +import org.springframework.test.web.servlet.RequestBuilder; + +import java.io.IOException; + +/** + * @BelongsProject: smart-cloud-server + * @BelongsPackage: com.zhilian.online.uitls + * @Author: LiYuan + * @CreateTime: 2024-04-17 21:41 + * @Description: mqtt工具类 + * @Version: 1.0 + */ +@Component +@Slf4j +public class MqttUtil { + + /** + * @description: 通过ip地址调用mqtt服务获取fluxmq的负载量 + * @author: LiYuan + * @param: ipAddress + * @return: Integer + **/ + public Integer getLoadInfoByIp(String ipAddress) { + + int num = 0; + + String URL = OnlineConstants.HTTP_PREFIX + ipAddress + OnlineConstants.FLUXMQ_INFO_URL; + + OkHttpClient client = new OkHttpClient(); + Request build = new Request.Builder() + .url(URL) + .get() + .addHeader("User-Agent","Apifox/1.0.0(https://apifox.com)") + .addHeader("AccessToken","") + .build(); + + try { + Response response = client.newCall(build).execute(); + JSONArray jsonArray = JSONArray.parseArray(response.body().string()); + JSONObject jsonObject = jsonArray.getJSONObject(0); + + //获取mqttInfo对象的值 + JSONObject mqttInfo = jsonObject.getJSONObject("mqttInfo"); + + //获取fluxmq链接数 + num = mqttInfo.getIntValue("connectSize"); + + log.info("{}的fluxMq链接数为:{}",ipAddress,num); + + } catch (IOException e) { + log.error(e.getMessage()); + } + + return num; + + } + +} diff --git a/zhilian-modules/zhilian-online/src/main/resources/mapper/online/OnlineGatherMapper.xml b/zhilian-modules/zhilian-online/src/main/resources/mapper/online/OnlineGatherMapper.xml deleted file mode 100644 index a9fbb43..0000000 --- a/zhilian-modules/zhilian-online/src/main/resources/mapper/online/OnlineGatherMapper.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - \ No newline at end of file