Compare commits
4 Commits
c08a1376d6
...
ec41019824
Author | SHA1 | Date |
---|---|---|
|
ec41019824 | |
|
b491045ebf | |
|
580172aa76 | |
|
3202af6ebb |
|
@ -12,7 +12,7 @@
|
||||||
<artifactId>cloud-common-kafka</artifactId>
|
<artifactId>cloud-common-kafka</artifactId>
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
cloud-common-kafka
|
cloud-common-kafka模块
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>cloud-common</artifactId>
|
||||||
|
<version>3.6.3</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>cloud-common-mqtt</artifactId>
|
||||||
|
|
||||||
|
<description>
|
||||||
|
cloud-common-mqtt消息队列遥测传输协议
|
||||||
|
</description>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- 项目公共核心模块 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>cloud-common-core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
|
@ -0,0 +1,31 @@
|
||||||
|
package com.muyu.common.mqtt;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mqtt连接配置
|
||||||
|
* @Author:李庆帅
|
||||||
|
* @Package:com.muyu.common.mqtt
|
||||||
|
* @Project:cloud-server
|
||||||
|
* @name:MQTTConnect
|
||||||
|
* @Date:2024/10/2 9:40
|
||||||
|
*/
|
||||||
|
public class MQTTConnect
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* String topic = "vehicle";
|
||||||
|
* String broker = "tcp://106.15.136.7:1883";
|
||||||
|
* String clientId = "JavaSample";
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定义主题字符串,用于MQTT消息交换的频道
|
||||||
|
*/
|
||||||
|
public static final String TOPIC="vehicle";
|
||||||
|
/**
|
||||||
|
*定义代理服务器的连接字符串,格式通常为协议名称,IP地址和端口号
|
||||||
|
*/
|
||||||
|
public static final String BROKER="tcp://106.15.136.7:1883";
|
||||||
|
/**
|
||||||
|
*定义客户端ID,用于在MQTT代理服务器中标识客户端
|
||||||
|
*/
|
||||||
|
public static final String CLIENT_ID ="JavaSample";
|
||||||
|
}
|
|
@ -24,6 +24,7 @@
|
||||||
<module>cloud-common-kafka</module>
|
<module>cloud-common-kafka</module>
|
||||||
<module>cloud-common-cache</module>
|
<module>cloud-common-cache</module>
|
||||||
<module>cloud-common-swagger</module>
|
<module>cloud-common-swagger</module>
|
||||||
|
<module>cloud-common-mqtt</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<artifactId>cloud-common</artifactId>
|
<artifactId>cloud-common</artifactId>
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package com.muyu.enterprise.cache;
|
package com.muyu.enterprise.cache;
|
||||||
|
|
||||||
import com.muyu.common.cache.config.CacheAbsBasic;
|
import com.muyu.common.cache.config.CacheAbsBasic;
|
||||||
import com.muyu.enterprise.domain.CarCompany;
|
|
||||||
import com.muyu.enterprise.domain.WarnRule;
|
import com.muyu.enterprise.domain.WarnRule;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -3,5 +3,5 @@ com.muyu.enterprise.cache.CarFaultCacheService
|
||||||
com.muyu.enterprise.cache.CarManageCacheService
|
com.muyu.enterprise.cache.CarManageCacheService
|
||||||
com.muyu.enterprise.cache.CarMessageCacheService
|
com.muyu.enterprise.cache.CarMessageCacheService
|
||||||
com.muyu.enterprise.cache.CarTemplateCacheService
|
com.muyu.enterprise.cache.CarTemplateCacheService
|
||||||
com.muyu.enterprise.cache.CarWarnCacheServic
|
com.muyu.enterprise.cache.CarWarnCacheService
|
||||||
com.muyu.enterprise.cache.ElectronicFenceCacheService
|
com.muyu.enterprise.cache.ElectronicFenceCacheService
|
||||||
|
|
|
@ -11,6 +11,10 @@
|
||||||
|
|
||||||
<artifactId>cloud-modules-enterprise-common</artifactId>
|
<artifactId>cloud-modules-enterprise-common</artifactId>
|
||||||
|
|
||||||
|
<description>
|
||||||
|
cloud-modules-enterprise-common企业业务平台服务
|
||||||
|
</description>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>cloud-modules-enterprise</artifactId>
|
||||||
|
<version>3.6.3</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>cloud-modules-enterprise-remote</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<description>
|
||||||
|
cloud-modules-enterprise-remote 企业远程调用模块
|
||||||
|
</description>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- 企业公共模块 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>cloud-modules-enterprise-common</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
|
@ -1,10 +1,9 @@
|
||||||
package com.muyu.analysis.parsing.remote;
|
package com.muyu.enterprise.remote;
|
||||||
|
|
||||||
import com.muyu.analysis.parsing.remote.factory.RemoteClientServiceFactory;
|
import com.muyu.enterprise.remote.factory.RemoteMessageValueServiceFactory;
|
||||||
import com.muyu.common.core.constant.ServiceNameConstants;
|
import com.muyu.common.core.constant.ServiceNameConstants;
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
import com.muyu.enterprise.domain.resp.car.MessageValueListResp;
|
import com.muyu.enterprise.domain.resp.car.MessageValueListResp;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
@ -12,34 +11,27 @@ import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 报文模版远程调用接口
|
* 报文数据服务
|
||||||
* @Author:李庆帅
|
* @Author:李庆帅
|
||||||
* @Package:com.muyu.analysis.parsing.feign
|
* @Package:com.muyu.analysis.parsing.feign
|
||||||
* @Project:cloud-server
|
* @Project:cloud-server
|
||||||
* @name:RemoteServiceClient
|
* @name:RemoteServiceClient
|
||||||
* @Date:2024/9/28 20:38
|
* @Date:2024/9/28 20:38
|
||||||
* ,,value = ServiceNameConstants.ENTERPRISE_SERVICE
|
|
||||||
* ,fallbackFactory= RemoteClientServiceFactory.class
|
|
||||||
*/
|
*/
|
||||||
@FeignClient(name = "cloud-enterprise",value = ServiceNameConstants.ENTERPRISE_SERVICE
|
@FeignClient(
|
||||||
,fallbackFactory= RemoteClientServiceFactory.class
|
path = "/messageValue",
|
||||||
|
contextId = "remoteMessageValueService",
|
||||||
|
value = ServiceNameConstants.ENTERPRISE_SERVICE,
|
||||||
|
fallbackFactory= RemoteMessageValueServiceFactory.class
|
||||||
)
|
)
|
||||||
public interface RemoteClientService {
|
public interface RemoteMessageValueService {
|
||||||
/**
|
|
||||||
* 根据报文模版id查询报文数据
|
|
||||||
* @param vehicleVin 请求对象
|
|
||||||
* @return 返回结果
|
|
||||||
*/
|
|
||||||
@GetMapping("/vehicleManage/findByVehicleVin/{vehicleVin}")
|
|
||||||
// @Operation(description = "通过车辆vin码查询模板id")
|
|
||||||
public Result<Long> findByVehicleVin(@PathVariable("vehicleVin") String vehicleVin);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据报文模版id查询报文数据
|
* 根据报文模版id查询报文数据
|
||||||
* @param templateId 请求对象
|
* @param templateId 请求对象
|
||||||
* @return 返回结果
|
* @return 返回结果
|
||||||
*/
|
*/
|
||||||
@GetMapping("/messageValue/findByTemplateId/{templateId}")
|
@GetMapping("/findByTemplateId/{templateId}")
|
||||||
// @Operation(summary = "根据报文模版id查询报文数据", description = "根据报文模版id查询报文数据")
|
// @Operation(summary = "根据报文模版id查询报文数据", description = "根据报文模版id查询报文数据")
|
||||||
public Result<List<MessageValueListResp>> findByTemplateId(@PathVariable("templateId") Long templateId);
|
public Result<List<MessageValueListResp>> findByTemplateId(@PathVariable("templateId") Long templateId);
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
package com.muyu.enterprise.remote;
|
||||||
|
|
||||||
|
import com.muyu.common.core.constant.ServiceNameConstants;
|
||||||
|
import com.muyu.common.core.domain.Result;
|
||||||
|
import com.muyu.enterprise.remote.factory.RemoteVehicleServiceFactory;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 车辆管理服务
|
||||||
|
* @Author:李庆帅
|
||||||
|
* @Package:com.muyu.enterprise.remote
|
||||||
|
* @Project:cloud-server
|
||||||
|
* @name:RemoteVehicleService
|
||||||
|
* @Date:2024/10/7 20:53
|
||||||
|
*/
|
||||||
|
@FeignClient(
|
||||||
|
path = "/vehicleManage",
|
||||||
|
contextId = "remoteVehicleService",
|
||||||
|
value = ServiceNameConstants.ENTERPRISE_SERVICE,
|
||||||
|
fallbackFactory= RemoteVehicleServiceFactory.class
|
||||||
|
)
|
||||||
|
public interface RemoteVehicleService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过车辆vin码查询模板id
|
||||||
|
* @param vehicleVin 请求对象
|
||||||
|
* @return 返回结果
|
||||||
|
*/
|
||||||
|
@GetMapping("/findByVehicleVin/{vehicleVin}")
|
||||||
|
public Result<Long> findByVehicleVin(@PathVariable("vehicleVin") String vehicleVin);
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
package com.muyu.analysis.parsing.remote.factory;
|
package com.muyu.enterprise.remote.factory;
|
||||||
|
|
||||||
import com.muyu.analysis.parsing.remote.RemoteClientService;
|
import com.muyu.enterprise.remote.RemoteMessageValueService;
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
import com.muyu.enterprise.domain.resp.car.MessageValueListResp;
|
import com.muyu.enterprise.domain.resp.car.MessageValueListResp;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -11,7 +11,7 @@ import org.springframework.stereotype.Component;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 报文模版对象服务降级处理
|
* 报文数据服务降级处理
|
||||||
* @Author:李庆帅
|
* @Author:李庆帅
|
||||||
* @Package:com.muyu.analysis.parsing.remote.factory
|
* @Package:com.muyu.analysis.parsing.remote.factory
|
||||||
* @Project:cloud-server
|
* @Project:cloud-server
|
||||||
|
@ -19,21 +19,15 @@ import java.util.List;
|
||||||
* @Date:2024/9/28 21:16
|
* @Date:2024/9/28 21:16
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
public class RemoteClientServiceFactory
|
public class RemoteMessageValueServiceFactory
|
||||||
implements FallbackFactory<RemoteClientService>
|
implements FallbackFactory<RemoteMessageValueService>
|
||||||
{
|
{
|
||||||
private static final Logger log = LoggerFactory.getLogger(RemoteClientServiceFactory.class);
|
private static final Logger log = LoggerFactory.getLogger(RemoteMessageValueServiceFactory.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RemoteClientService create(Throwable throwable) {
|
public RemoteMessageValueService create(Throwable throwable) {
|
||||||
log.error("报文模版传参调用失败:{}", throwable.getMessage());
|
log.error("报文模版传参调用失败:{}", throwable.getMessage());
|
||||||
return new RemoteClientService(){
|
return new RemoteMessageValueService(){
|
||||||
|
|
||||||
@Override
|
|
||||||
public Result<Long> findByVehicleVin(String vehicleVin) {
|
|
||||||
return Result.error("报文模版传参调用失败" + throwable.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result<List<MessageValueListResp>> findByTemplateId(Long templateId) {
|
public Result<List<MessageValueListResp>> findByTemplateId(Long templateId) {
|
||||||
return Result.error("报文模版传参调用失败" + throwable.getMessage());
|
return Result.error("报文模版传参调用失败" + throwable.getMessage());
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.muyu.enterprise.remote.factory;
|
||||||
|
|
||||||
|
import com.muyu.common.core.domain.Result;
|
||||||
|
import com.muyu.enterprise.domain.resp.car.MessageValueListResp;
|
||||||
|
import com.muyu.enterprise.remote.RemoteVehicleService;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 车辆管理服务降级处理
|
||||||
|
* @Author:李庆帅
|
||||||
|
* @Package:com.muyu.enterprise.remote.factory
|
||||||
|
* @Project:cloud-server
|
||||||
|
* @name:RemoteVehicleServiceFactory
|
||||||
|
* @Date:2024/10/7 20:57
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class RemoteVehicleServiceFactory implements FallbackFactory<RemoteVehicleService> {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(RemoteVehicleServiceFactory.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RemoteVehicleService create(Throwable throwable) {
|
||||||
|
return new RemoteVehicleService() {
|
||||||
|
@Override
|
||||||
|
public Result<Long> findByVehicleVin(String vehicleVin) {
|
||||||
|
return Result.error("报文模版传参调用失败" + throwable.getMessage());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
com.muyu.enterprise.remote.factory.RemoteVehicleServiceFactory
|
||||||
|
com.muyu.enterprise.remote.factory.RemoteMessageValueServiceFactory
|
|
@ -16,6 +16,7 @@
|
||||||
<module>cloud-modules-enterprise-server</module>
|
<module>cloud-modules-enterprise-server</module>
|
||||||
<module>cloud-modules-enterprise-common</module>
|
<module>cloud-modules-enterprise-common</module>
|
||||||
<module>cloud-modules-enterprise-cache</module>
|
<module>cloud-modules-enterprise-cache</module>
|
||||||
|
<module>cloud-modules-enterprise-remote</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
|
|
|
@ -89,17 +89,10 @@
|
||||||
<groupId>com.muyu</groupId>
|
<groupId>com.muyu</groupId>
|
||||||
<artifactId>cloud-modules-enterprise-common</artifactId>
|
<artifactId>cloud-modules-enterprise-common</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- 协议解析 - 公共依赖 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.muyu</groupId>
|
|
||||||
<artifactId>cloud-modules-enterprise-server</artifactId>
|
|
||||||
<version>3.6.3</version>
|
|
||||||
</dependency>
|
|
||||||
<!-- mybatis-plus-join依赖 -->
|
<!-- mybatis-plus-join依赖 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.yulichang</groupId>
|
<groupId>com.github.yulichang</groupId>
|
||||||
<artifactId>mybatis-plus-join-boot-starter</artifactId>
|
<artifactId>mybatis-plus-join</artifactId>
|
||||||
<version>1.4.11</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- 核心模块 - 公共依赖 -->
|
<!-- 核心模块 - 公共依赖 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -111,6 +104,26 @@
|
||||||
<groupId>com.muyu</groupId>
|
<groupId>com.muyu</groupId>
|
||||||
<artifactId>cloud-common-kafka</artifactId>
|
<artifactId>cloud-common-kafka</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- mqtt消息队列遥测传输协议服务 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>cloud-common-mqtt</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- Spring Boot的缓存启动器 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-cache</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- 高性能的Java缓存库缓存解决方案 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.ben-manes.caffeine</groupId>
|
||||||
|
<artifactId>caffeine</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- 企业远程模块 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>cloud-modules-enterprise-remote</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
package com.muyu.analysis.parsing.MQTT;
|
package com.muyu.analysis.parsing.mqtt;
|
||||||
|
|
||||||
import com.muyu.analysis.parsing.remote.RemoteClientService;
|
|
||||||
import com.muyu.common.core.constant.KafkaConstants;
|
import com.muyu.common.core.constant.KafkaConstants;
|
||||||
import com.muyu.common.core.constant.RedisConstants;
|
import com.muyu.common.core.constant.RedisConstants;
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
|
import com.muyu.common.mqtt.MQTTConnect;
|
||||||
import com.muyu.enterprise.domain.resp.car.MessageValueListResp;
|
import com.muyu.enterprise.domain.resp.car.MessageValueListResp;
|
||||||
|
import com.muyu.enterprise.remote.RemoteMessageValueService;
|
||||||
|
import com.muyu.enterprise.remote.RemoteVehicleService;
|
||||||
import jakarta.annotation.PostConstruct;
|
import jakarta.annotation.PostConstruct;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import cn.hutool.json.JSONObject;
|
import cn.hutool.json.JSONObject;
|
||||||
|
@ -34,29 +36,32 @@ public class ParsingMQTT {
|
||||||
@Resource
|
@Resource
|
||||||
private RedisTemplate<String, Object> redisTemplate;
|
private RedisTemplate<String, Object> redisTemplate;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private RemoteClientService remoteServiceClient;
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private KafkaProducer<String, String> kafkaProducer;
|
private KafkaProducer<String, String> kafkaProducer;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private RemoteVehicleService remoteVehicleService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private RemoteMessageValueService remoteMessageValueService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 协议解析
|
* 协议解析
|
||||||
*/
|
*/
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void mqttClient() {
|
public void mqttClient() {
|
||||||
String topic = "vehicle";
|
// String topic = "vehicle";
|
||||||
String broker = "tcp://106.15.136.7:1883";
|
//// String MQTTConnect.BROKER = "tcp://106.15.136.7:1883";
|
||||||
String clientId = "JavaSample";
|
//// String clientId = "JavaSample";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 第三个参数为空,默认持久化策略
|
// 第三个参数为空,默认持久化策略
|
||||||
MqttClient sampleClient = new MqttClient(broker, clientId);
|
MqttClient sampleClient = new MqttClient(MQTTConnect.BROKER, MQTTConnect.CLIENT_ID);
|
||||||
MqttConnectOptions connOpts = new MqttConnectOptions();
|
MqttConnectOptions connOpts = new MqttConnectOptions();
|
||||||
connOpts.setCleanSession(true);
|
connOpts.setCleanSession(true);
|
||||||
System.out.println("Connecting to broker: " + broker);
|
log.info("Connecting to MQTTConnect.BROKER: {}", MQTTConnect.BROKER);
|
||||||
sampleClient.connect(connOpts);
|
sampleClient.connect(connOpts);
|
||||||
sampleClient.subscribe(topic, 0);
|
sampleClient.subscribe(MQTTConnect.TOPIC, 0);
|
||||||
sampleClient.setCallback(new MqttCallback() {
|
sampleClient.setCallback(new MqttCallback() {
|
||||||
// 连接丢失
|
// 连接丢失
|
||||||
@Override
|
@Override
|
||||||
|
@ -95,7 +100,7 @@ public class ParsingMQTT {
|
||||||
String vehicleVin = result.substring(1, 18);
|
String vehicleVin = result.substring(1, 18);
|
||||||
log.info("车辆VIN码: " + vehicleVin);
|
log.info("车辆VIN码: " + vehicleVin);
|
||||||
//根据车辆VIN码查询报文模板ID
|
//根据车辆VIN码查询报文模板ID
|
||||||
Result<Long> byVehicleVin = remoteServiceClient.findByVehicleVin(vehicleVin);
|
Result<Long> byVehicleVin = remoteVehicleService.findByVehicleVin(vehicleVin);
|
||||||
Long templateId = byVehicleVin.getData();
|
Long templateId = byVehicleVin.getData();
|
||||||
List<MessageValueListResp> templateList;
|
List<MessageValueListResp> templateList;
|
||||||
//从redis缓存中获取报文模板数据
|
//从redis缓存中获取报文模板数据
|
||||||
|
@ -108,7 +113,7 @@ public class ParsingMQTT {
|
||||||
.toList();
|
.toList();
|
||||||
log.info("Redis缓存查询成功");
|
log.info("Redis缓存查询成功");
|
||||||
} else {
|
} else {
|
||||||
Result<List<MessageValueListResp>> byTemplateId = remoteServiceClient.findByTemplateId(templateId);
|
Result<List<MessageValueListResp>> byTemplateId = remoteMessageValueService.findByTemplateId(templateId);
|
||||||
templateList = byTemplateId.getData();
|
templateList = byTemplateId.getData();
|
||||||
templateList.forEach(
|
templateList.forEach(
|
||||||
listResp ->
|
listResp ->
|
||||||
|
@ -154,6 +159,11 @@ public class ParsingMQTT {
|
||||||
log.info("loc " + me.getLocalizedMessage());
|
log.info("loc " + me.getLocalizedMessage());
|
||||||
log.info("cause " + me.getCause());
|
log.info("cause " + me.getCause());
|
||||||
log.info("excep " + me);
|
log.info("excep " + me);
|
||||||
|
System.out.println("reason " + me.getReasonCode());
|
||||||
|
System.out.println("msg " + me.getMessage());
|
||||||
|
System.out.println("loc " + me.getLocalizedMessage());
|
||||||
|
System.out.println("cause " + me.getCause());
|
||||||
|
System.out.println("excep " + me);
|
||||||
me.printStackTrace();
|
me.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,86 @@
|
||||||
|
package com.muyu.analysis.parsing.mqtt;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.w3c.dom.stylesheets.LinkStyle;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:李庆帅
|
||||||
|
* @Package:com.muyu.analysis.parsing.mqtt
|
||||||
|
* @Project:cloud-server
|
||||||
|
* @name:Test2
|
||||||
|
* @Date:2024/10/6 20:36
|
||||||
|
*/
|
||||||
|
@Log4j2
|
||||||
|
public class Test2
|
||||||
|
{
|
||||||
|
private static final int DURATION_SECONDS = 5;
|
||||||
|
private static List<JSONObject> receivedStrings = new ArrayList<>();
|
||||||
|
private static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
||||||
|
private static int elapsedSeconds = 0;
|
||||||
|
private static String file = "elapsed" ;
|
||||||
|
|
||||||
|
public static void main(String[] args){
|
||||||
|
//定义一个任务,每秒执行一次
|
||||||
|
Runnable task = new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
JSONObject stringFromSource = getStringFromSource();
|
||||||
|
receivedStrings.add(stringFromSource);
|
||||||
|
System.out.println("Received:"+stringFromSource);
|
||||||
|
//清理超过的数据
|
||||||
|
cleanUpOIdStrings();
|
||||||
|
//检查超速条件
|
||||||
|
checkForSpeeding();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
//每个1秒执行一次任务
|
||||||
|
scheduler.scheduleAtFixedRate(task,0,1, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
//模拟从某个源获取字符串的方法
|
||||||
|
private static JSONObject getStringFromSource(){
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.put("message","Hello World");
|
||||||
|
jsonObject.put("time",System.currentTimeMillis());
|
||||||
|
jsonObject.put("elapsed",elapsedSeconds);
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
//清理超过60秒的数据
|
||||||
|
private static void cleanUpOIdStrings(){
|
||||||
|
long currentTime = System.currentTimeMillis();
|
||||||
|
receivedStrings.removeIf(jsonObject ->currentTime-jsonObject.getLong("time")>TimeUnit.SECONDS.toMicros(DURATION_SECONDS));
|
||||||
|
}
|
||||||
|
|
||||||
|
//检查是否有超速情况
|
||||||
|
private static void checkForSpeeding()
|
||||||
|
{
|
||||||
|
if(receivedStrings.size() < 2)return;//如果数据不足,直接返回
|
||||||
|
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.put("message","你好");
|
||||||
|
jsonObject.put("time",System.currentTimeMillis());
|
||||||
|
jsonObject.put("elapsed",10);
|
||||||
|
|
||||||
|
for (int i = 0; i < receivedStrings.size(); i++) {
|
||||||
|
JSONObject current = receivedStrings.get(i);
|
||||||
|
JSONObject next = receivedStrings.get(i + 1);
|
||||||
|
|
||||||
|
Short currentElapsed = current.getShort(file);
|
||||||
|
Short nextElapsed = next.getShort(file);
|
||||||
|
receivedStrings.add(jsonObject);
|
||||||
|
//检查条件,如果相差大于12,则记录错误
|
||||||
|
if (nextElapsed - currentElapsed > 12) {
|
||||||
|
System.out.println("出错啦!出错啦!车子超速啦!!!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -1 +0,0 @@
|
||||||
com.muyu.analysis.parsing.remote.factory.RemoteClientServiceFactory
|
|
|
@ -7,7 +7,7 @@ nacos:
|
||||||
addr: 106.15.136.7:8848
|
addr: 106.15.136.7:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: lqs
|
namespace: dev
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
application:
|
application:
|
||||||
|
|
16
pom.xml
16
pom.xml
|
@ -375,6 +375,13 @@
|
||||||
<version>${muyu.version}</version>
|
<version>${muyu.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- mqtt消息队列遥测传输协议服务 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>cloud-common-mqtt</artifactId>
|
||||||
|
<version>${muyu.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- 公共缓存模块 -->
|
<!-- 公共缓存模块 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.muyu</groupId>
|
<groupId>com.muyu</groupId>
|
||||||
|
@ -382,6 +389,13 @@
|
||||||
<version>${muyu.version}</version>
|
<version>${muyu.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 企业远程模块 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>cloud-modules-enterprise-remote</artifactId>
|
||||||
|
<version>${muyu.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- 企业缓存模块 -->
|
<!-- 企业缓存模块 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.muyu</groupId>
|
<groupId>com.muyu</groupId>
|
||||||
|
@ -395,6 +409,8 @@
|
||||||
<artifactId>cloud-modules-enterprise-common</artifactId>
|
<artifactId>cloud-modules-enterprise-common</artifactId>
|
||||||
<version>${muyu.version}</version>
|
<version>${muyu.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue