feat(): 新增企业远程调用模块,重构远程调用代码
parent
580172aa76
commit
b491045ebf
|
@ -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.domain.Result;
|
||||
import com.muyu.enterprise.domain.resp.car.MessageValueListResp;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
@ -12,34 +11,27 @@ import org.springframework.web.bind.annotation.PathVariable;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 报文模版远程调用接口
|
||||
* 报文数据服务
|
||||
* @Author:李庆帅
|
||||
* @Package:com.muyu.analysis.parsing.feign
|
||||
* @Project:cloud-server
|
||||
* @name:RemoteServiceClient
|
||||
* @Date:2024/9/28 20:38
|
||||
* ,,value = ServiceNameConstants.ENTERPRISE_SERVICE
|
||||
* ,fallbackFactory= RemoteClientServiceFactory.class
|
||||
*/
|
||||
@FeignClient(name = "cloud-enterprise",value = ServiceNameConstants.ENTERPRISE_SERVICE
|
||||
,fallbackFactory= RemoteClientServiceFactory.class
|
||||
@FeignClient(
|
||||
path = "/messageValue",
|
||||
contextId = "remoteMessageValueService",
|
||||
value = ServiceNameConstants.ENTERPRISE_SERVICE,
|
||||
fallbackFactory= RemoteMessageValueServiceFactory.class
|
||||
)
|
||||
public interface RemoteClientService {
|
||||
/**
|
||||
* 根据报文模版id查询报文数据
|
||||
* @param vehicleVin 请求对象
|
||||
* @return 返回结果
|
||||
*/
|
||||
@GetMapping("/vehicleManage/findByVehicleVin/{vehicleVin}")
|
||||
// @Operation(description = "通过车辆vin码查询模板id")
|
||||
public Result<Long> findByVehicleVin(@PathVariable("vehicleVin") String vehicleVin);
|
||||
public interface RemoteMessageValueService {
|
||||
|
||||
/**
|
||||
* 根据报文模版id查询报文数据
|
||||
* @param templateId 请求对象
|
||||
* @return 返回结果
|
||||
*/
|
||||
@GetMapping("/messageValue/findByTemplateId/{templateId}")
|
||||
@GetMapping("/findByTemplateId/{templateId}")
|
||||
// @Operation(summary = "根据报文模版id查询报文数据", description = "根据报文模版id查询报文数据")
|
||||
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.enterprise.domain.resp.car.MessageValueListResp;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -11,7 +11,7 @@ import org.springframework.stereotype.Component;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 报文模版对象服务降级处理
|
||||
* 报文数据服务降级处理
|
||||
* @Author:李庆帅
|
||||
* @Package:com.muyu.analysis.parsing.remote.factory
|
||||
* @Project:cloud-server
|
||||
|
@ -19,21 +19,15 @@ import java.util.List;
|
|||
* @Date:2024/9/28 21:16
|
||||
*/
|
||||
@Component
|
||||
public class RemoteClientServiceFactory
|
||||
implements FallbackFactory<RemoteClientService>
|
||||
public class RemoteMessageValueServiceFactory
|
||||
implements FallbackFactory<RemoteMessageValueService>
|
||||
{
|
||||
private static final Logger log = LoggerFactory.getLogger(RemoteClientServiceFactory.class);
|
||||
private static final Logger log = LoggerFactory.getLogger(RemoteMessageValueServiceFactory.class);
|
||||
|
||||
@Override
|
||||
public RemoteClientService create(Throwable throwable) {
|
||||
public RemoteMessageValueService create(Throwable throwable) {
|
||||
log.error("报文模版传参调用失败:{}", throwable.getMessage());
|
||||
return new RemoteClientService(){
|
||||
|
||||
@Override
|
||||
public Result<Long> findByVehicleVin(String vehicleVin) {
|
||||
return Result.error("报文模版传参调用失败" + throwable.getMessage());
|
||||
}
|
||||
|
||||
return new RemoteMessageValueService(){
|
||||
@Override
|
||||
public Result<List<MessageValueListResp>> findByTemplateId(Long templateId) {
|
||||
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-common</module>
|
||||
<module>cloud-modules-enterprise-cache</module>
|
||||
<module>cloud-modules-enterprise-remote</module>
|
||||
</modules>
|
||||
|
||||
<description>
|
||||
|
|
|
@ -89,17 +89,10 @@
|
|||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-modules-enterprise-common</artifactId>
|
||||
</dependency>
|
||||
<!-- 协议解析 - 公共依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-modules-enterprise-server</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
<!-- mybatis-plus-join依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.github.yulichang</groupId>
|
||||
<artifactId>mybatis-plus-join-boot-starter</artifactId>
|
||||
<version>1.4.11</version>
|
||||
<artifactId>mybatis-plus-join</artifactId>
|
||||
</dependency>
|
||||
<!-- 核心模块 - 公共依赖 -->
|
||||
<dependency>
|
||||
|
@ -125,7 +118,11 @@
|
|||
<dependency>
|
||||
<groupId>com.github.ben-manes.caffeine</groupId>
|
||||
<artifactId>caffeine</artifactId>
|
||||
<version>3.1.8</version>
|
||||
</dependency>
|
||||
<!-- 企业远程模块 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-modules-enterprise-remote</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
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.RedisConstants;
|
||||
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.remote.RemoteMessageValueService;
|
||||
import com.muyu.enterprise.remote.RemoteVehicleService;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.annotation.Resource;
|
||||
import cn.hutool.json.JSONObject;
|
||||
|
@ -35,12 +36,15 @@ public class ParsingMQTT {
|
|||
@Resource
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
@Autowired
|
||||
private RemoteClientService remoteServiceClient;
|
||||
|
||||
@Resource
|
||||
private KafkaProducer<String, String> kafkaProducer;
|
||||
|
||||
@Resource
|
||||
private RemoteVehicleService remoteVehicleService;
|
||||
|
||||
@Resource
|
||||
private RemoteMessageValueService remoteMessageValueService;
|
||||
|
||||
/**
|
||||
* 协议解析
|
||||
*/
|
||||
|
@ -55,7 +59,7 @@ public class ParsingMQTT {
|
|||
MqttClient sampleClient = new MqttClient(MQTTConnect.BROKER, MQTTConnect.CLIENT_ID);
|
||||
MqttConnectOptions connOpts = new MqttConnectOptions();
|
||||
connOpts.setCleanSession(true);
|
||||
System.out.println("Connecting to MQTTConnect.BROKER: " + MQTTConnect.BROKER);
|
||||
log.info("Connecting to MQTTConnect.BROKER: {}", MQTTConnect.BROKER);
|
||||
sampleClient.connect(connOpts);
|
||||
sampleClient.subscribe(MQTTConnect.TOPIC, 0);
|
||||
sampleClient.setCallback(new MqttCallback() {
|
||||
|
@ -96,7 +100,7 @@ public class ParsingMQTT {
|
|||
String vehicleVin = result.substring(1, 18);
|
||||
log.info("车辆VIN码: " + vehicleVin);
|
||||
//根据车辆VIN码查询报文模板ID
|
||||
Result<Long> byVehicleVin = remoteServiceClient.findByVehicleVin(vehicleVin);
|
||||
Result<Long> byVehicleVin = remoteVehicleService.findByVehicleVin(vehicleVin);
|
||||
Long templateId = byVehicleVin.getData();
|
||||
List<MessageValueListResp> templateList;
|
||||
//从redis缓存中获取报文模板数据
|
||||
|
@ -109,7 +113,7 @@ public class ParsingMQTT {
|
|||
.toList();
|
||||
log.info("Redis缓存查询成功");
|
||||
} else {
|
||||
Result<List<MessageValueListResp>> byTemplateId = remoteServiceClient.findByTemplateId(templateId);
|
||||
Result<List<MessageValueListResp>> byTemplateId = remoteMessageValueService.findByTemplateId(templateId);
|
||||
templateList = byTemplateId.getData();
|
||||
templateList.forEach(
|
||||
listResp ->
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
com.muyu.analysis.parsing.remote.factory.RemoteClientServiceFactory
|
27
pom.xml
27
pom.xml
|
@ -375,6 +375,13 @@
|
|||
<version>${muyu.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- mqtt消息队列遥测传输协议服务 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-mqtt</artifactId>
|
||||
<version>${muyu.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 公共缓存模块 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
|
@ -382,6 +389,13 @@
|
|||
<version>${muyu.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 企业远程模块 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-modules-enterprise-remote</artifactId>
|
||||
<version>${muyu.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 企业缓存模块 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
|
@ -396,18 +410,7 @@
|
|||
<version>${muyu.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 协议解析模块 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-modules-protocol-analysis</artifactId>
|
||||
<version>${muyu.version}</version>
|
||||
</dependency>
|
||||
<!-- mqtt消息队列遥测传输协议服务 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-mqtt</artifactId>
|
||||
<version>${muyu.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
|
Loading…
Reference in New Issue