fate():新增协议解析模块:MQTT连接,数据转换JSON数据
parent
b70a552b6a
commit
681c88db28
|
@ -29,5 +29,17 @@
|
||||||
<groupId>io.swagger.core.v3</groupId>
|
<groupId>io.swagger.core.v3</groupId>
|
||||||
<artifactId>swagger-annotations-jakarta</artifactId>
|
<artifactId>swagger-annotations-jakarta</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!--mqttv3依赖-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.paho</groupId>
|
||||||
|
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
|
||||||
|
<version>1.2.2</version>
|
||||||
|
</dependency>
|
||||||
|
<!--mqtt依赖-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.integration</groupId>
|
||||||
|
<artifactId>spring-integration-mqtt</artifactId>
|
||||||
|
<version>6.2.5</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
|
@ -23,15 +23,9 @@
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.eclipse.paho</groupId>
|
<groupId>com.github.yulichang</groupId>
|
||||||
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
|
<artifactId>mybatis-plus-join-boot-starter</artifactId>
|
||||||
<version>1.2.2</version>
|
<version>1.4.11</version>
|
||||||
</dependency>
|
|
||||||
<!--mqtt依赖-->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.integration</groupId>
|
|
||||||
<artifactId>spring-integration-mqtt</artifactId>
|
|
||||||
<version>6.2.5</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- SpringCloud Alibaba Nacos -->
|
<!-- SpringCloud Alibaba Nacos -->
|
||||||
|
|
|
@ -16,8 +16,26 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
public class CloudEnterpriseApplication {
|
public class CloudEnterpriseApplication {
|
||||||
public static void main (String[] args) {
|
public static void main (String[] args) {
|
||||||
SpringApplication.run(CloudEnterpriseApplication.class, args);
|
SpringApplication.run(CloudEnterpriseApplication.class, args);
|
||||||
while (true){
|
System.out.println(" _ooOoo_\n" +
|
||||||
System.out.println("马叉,马叉");
|
" o8888888o\n" +
|
||||||
}
|
" 88\" . \"88\n" +
|
||||||
|
" (| -_- |)\n" +
|
||||||
|
" O\\ = /O\n" +
|
||||||
|
" ____/`---'\\____\n" +
|
||||||
|
" .' \\\\| |// `.\n" +
|
||||||
|
" / \\\\||| : |||// \\\n" +
|
||||||
|
" / _||||| -:- |||||- \\\n" +
|
||||||
|
" | | \\\\\\ - /// | |\n" +
|
||||||
|
" | \\_| ''\\---/'' | |\n" +
|
||||||
|
" \\ .-\\__ `-` ___/-. /\n" +
|
||||||
|
" ___`. .' /--.--\\ `. . __\n" +
|
||||||
|
" .\"\" '< `.___\\_<|>_/___.' >'\"\".\n" +
|
||||||
|
" | | : `- \\`.;`\\ _ /`;.`/ - ` : | |\n" +
|
||||||
|
" \\ \\ `-. \\_ __\\ /__ _/ .-` / /\n" +
|
||||||
|
" ======`-.____`-.___\\_____/___.-`____.-'======\n" +
|
||||||
|
" `=---='\n" +
|
||||||
|
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
|
||||||
|
" // 佛祖保佑 永不宕机 永无BUG //");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.muyu.enterprise.mapper.car;
|
||||||
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.github.yulichang.base.MPJBaseMapper;
|
||||||
import com.muyu.enterprise.domain.car.Vehicle;
|
import com.muyu.enterprise.domain.car.Vehicle;
|
||||||
import com.muyu.enterprise.domain.req.car.VehicleManageReq;
|
import com.muyu.enterprise.domain.req.car.VehicleManageReq;
|
||||||
import com.muyu.enterprise.domain.resp.car.VehicleManageResp;
|
import com.muyu.enterprise.domain.resp.car.VehicleManageResp;
|
||||||
|
@ -19,7 +20,7 @@ import java.util.List;
|
||||||
* @Description: 车辆管理持久层
|
* @Description: 车辆管理持久层
|
||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface VehicleMapper extends BaseMapper<Vehicle>
|
public interface VehicleMapper extends MPJBaseMapper<Vehicle>
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* 查询车辆管理列表
|
* 查询车辆管理列表
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
package com.muyu.enterprise.service.impl.carImpl;
|
package com.muyu.enterprise.service.impl.carImpl;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||||
|
import com.muyu.common.core.utils.StringUtils;
|
||||||
import com.muyu.enterprise.domain.car.Vehicle;
|
import com.muyu.enterprise.domain.car.Vehicle;
|
||||||
|
import com.muyu.enterprise.domain.car.VehicleType;
|
||||||
import com.muyu.enterprise.domain.req.car.VehicleManageReq;
|
import com.muyu.enterprise.domain.req.car.VehicleManageReq;
|
||||||
import com.muyu.enterprise.domain.resp.car.VehicleManageResp;
|
import com.muyu.enterprise.domain.resp.car.VehicleManageResp;
|
||||||
import com.muyu.enterprise.mapper.car.VehicleMapper;
|
import com.muyu.enterprise.mapper.car.VehicleMapper;
|
||||||
|
@ -36,8 +39,24 @@ extends ServiceImpl<VehicleMapper,
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<VehicleManageResp> getVehicleList(VehicleManageReq vehicleManageReq) {
|
public List<VehicleManageResp> getVehicleList(VehicleManageReq vehicleManageReq) {
|
||||||
List<VehicleManageResp> vehicleList = vehicleMapper.findAll(vehicleManageReq);
|
MPJLambdaWrapper<Vehicle> wrapper = new MPJLambdaWrapper<>();
|
||||||
return vehicleList;
|
wrapper.selectAll(Vehicle.class)
|
||||||
|
.selectAs(VehicleType::getVehicleTypeName, VehicleManageResp::getVehicleTypeName)
|
||||||
|
.leftJoin(VehicleType.class, VehicleType::getVehicleTypeId, Vehicle::getVehicleTypeId)
|
||||||
|
.like(
|
||||||
|
StringUtils.isNotEmpty(vehicleManageReq.getLicenceNumber()),
|
||||||
|
Vehicle::getLicenceNumber, vehicleManageReq.getLicenceNumber()
|
||||||
|
)
|
||||||
|
.like(
|
||||||
|
StringUtils.isNotEmpty(vehicleManageReq.getVehicleVin()),
|
||||||
|
Vehicle::getVehicleVin, vehicleManageReq.getVehicleVin()
|
||||||
|
)
|
||||||
|
.eq(
|
||||||
|
StringUtils.isNotBlank(vehicleManageReq.getVehicleStatus()),
|
||||||
|
Vehicle::getVehicleStatus, vehicleManageReq.getVehicleStatus()
|
||||||
|
);
|
||||||
|
List<VehicleManageResp> list = vehicleMapper.selectJoinList(VehicleManageResp.class, wrapper);
|
||||||
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,117 @@
|
||||||
|
<?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-protocol-analysis</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-protocol-analysis协议解析模块
|
||||||
|
</description>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- SpringCloud Alibaba Nacos -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- SpringCloud Alibaba Nacos Config -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- SpringCloud Alibaba Sentinel -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- SpringBoot Actuator -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Mysql Connector -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-j</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- MuYu Common DataSource -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>cloud-common-datasource</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- MuYu Common DataScope -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>cloud-common-datascope</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- MuYu Common Log -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>cloud-common-log</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 接口模块 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>cloud-common-api-doc</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 企业业务平台 - 公共依赖 -->
|
||||||
|
<dependency>
|
||||||
|
<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>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.yulichang</groupId>
|
||||||
|
<artifactId>mybatis-plus-join-boot-starter</artifactId>
|
||||||
|
<version>1.4.11</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<finalName>${project.artifactId}</finalName>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>repackage</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
|
@ -1,18 +1,18 @@
|
||||||
package com.muyu.enterprise.MQTT;
|
package com.muyu.analysis.parsing.MQTT;
|
||||||
|
|
||||||
|
import com.muyu.analysis.parsing.controller.ParsingController;
|
||||||
import org.eclipse.paho.client.mqttv3.*;
|
import org.eclipse.paho.client.mqttv3.*;
|
||||||
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 测试MQTT
|
* 测试MQTT
|
||||||
* @ClassName demo
|
* @ClassName demo
|
||||||
* @Description 描述
|
* @Description 描述
|
||||||
* @Author YiBo.Liu
|
* @Author 李庆帅
|
||||||
* @Date 2024/9/27 22:27
|
* @Date 2024/9/28
|
||||||
*/
|
*/
|
||||||
public class DemoMQTT {
|
public class DemoMQTT {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public void main(String[] args) {
|
||||||
|
|
||||||
String topic = "vehicle";
|
String topic = "vehicle";
|
||||||
String content = "Message from MqttPublishSample";
|
String content = "Message from MqttPublishSample";
|
||||||
|
@ -20,6 +20,8 @@ public class DemoMQTT {
|
||||||
String broker = "tcp://106.15.136.7:1883";
|
String 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(broker, clientId);
|
||||||
|
@ -55,4 +57,5 @@ public class DemoMQTT {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.muyu.analysis.parsing;
|
||||||
|
|
||||||
|
import com.muyu.common.security.annotation.EnableCustomConfig;
|
||||||
|
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 协议解析启动类
|
||||||
|
* @Author: 李庆帅
|
||||||
|
* @Package: com.muyu.cloud.protocol.parsing
|
||||||
|
* @Project: 2112-car-cloud-server
|
||||||
|
* @name: ProtocolParsingApplication
|
||||||
|
* @Date: 2024/9/28 11:54
|
||||||
|
* @Description: 协议解析启动类
|
||||||
|
*/
|
||||||
|
@EnableCustomConfig
|
||||||
|
@EnableMyFeignClients
|
||||||
|
@SpringBootApplication
|
||||||
|
public class ProtocolParsingApplication {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(ProtocolParsingApplication.class, args);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,87 @@
|
||||||
|
package com.muyu.analysis.parsing.controller;
|
||||||
|
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
|
import com.muyu.analysis.parsing.MQTT.DemoMQTT;
|
||||||
|
import com.muyu.analysis.parsing.service.ParsingService;
|
||||||
|
import org.eclipse.paho.client.mqttv3.*;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 协议解析控制层
|
||||||
|
* @Author:李庆帅
|
||||||
|
* @Package:com.muyu.analysis.parsing.controller
|
||||||
|
* @Project:cloud-server
|
||||||
|
* @name:ParsingController
|
||||||
|
* @Date:2024/9/28 20:36
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/parsing")
|
||||||
|
public class ParsingController
|
||||||
|
{
|
||||||
|
private static final String topic = "vehicle";
|
||||||
|
private static final String content = "Message from MqttPublishSample";
|
||||||
|
private static final int qos = 2;
|
||||||
|
private static final String broker = "tcp://106.15.136.7:1883";
|
||||||
|
private static final String clientId = "JavaSample";
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ParsingService parsingService;
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * 协议解析
|
||||||
|
// * @param messageStr
|
||||||
|
// * @return
|
||||||
|
// */
|
||||||
|
// @PostMapping("/protocolParsing")
|
||||||
|
// public JSONObject protocolParsing(@RequestParam("messageStr") String messageStr) {
|
||||||
|
// try {
|
||||||
|
// // 第三个参数为空,默认持久化策略
|
||||||
|
// MqttClient sampleClient = new MqttClient(broker, clientId);
|
||||||
|
// MqttConnectOptions connOpts = new MqttConnectOptions();
|
||||||
|
// connOpts.setCleanSession(true);
|
||||||
|
// System.out.println("Connecting to broker: "+broker);
|
||||||
|
// sampleClient.connect(connOpts);
|
||||||
|
// sampleClient.subscribe(topic,0);
|
||||||
|
// sampleClient.setCallback(new MqttCallback() {
|
||||||
|
// // 连接丢失
|
||||||
|
// @Override
|
||||||
|
// public void connectionLost(Throwable throwable) {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// // 连接成功
|
||||||
|
// @Override
|
||||||
|
// public void messageArrived(String s, MqttMessage mqttMessage) throws Exception {
|
||||||
|
// System.out.println(new String(mqttMessage.getPayload()));
|
||||||
|
// }
|
||||||
|
// // 接收信息
|
||||||
|
// @Override
|
||||||
|
// public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// } catch(MqttException 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();
|
||||||
|
// }
|
||||||
|
// JSONObject messageValue = parsingService.protocolParsing(messageStr);
|
||||||
|
// return messageValue;
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 协议解析
|
||||||
|
*/
|
||||||
|
@PostMapping("/mqttClient")
|
||||||
|
public void mqttClient() {
|
||||||
|
parsingService.mqtt();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.muyu.analysis.parsing.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.muyu.enterprise.domain.car.MessageValue;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 协议解析持久层
|
||||||
|
* @Author:李庆帅
|
||||||
|
* @Package:com.muyu.analysis.parsing.mapper
|
||||||
|
* @Project:cloud-server
|
||||||
|
* @name:ParsingMapper
|
||||||
|
* @Date:2024/9/28 20:54
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface ParsingMapper extends BaseMapper<MessageValue> {
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
package com.muyu.analysis.parsing.remote;
|
||||||
|
|
||||||
|
import com.muyu.analysis.parsing.remote.factory.RemoteClientServiceFactory;
|
||||||
|
import com.muyu.common.core.domain.Result;
|
||||||
|
import com.muyu.enterprise.domain.resp.car.MessageValueListResp;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
@FeignClient(name = "remoteClientService"
|
||||||
|
,fallbackFactory= RemoteClientServiceFactory.class)
|
||||||
|
public interface RemoteClientService {
|
||||||
|
/**
|
||||||
|
* 根据报文模版id查询报文数据
|
||||||
|
* @param vehicleVin 请求对象
|
||||||
|
* @return 返回结果
|
||||||
|
*/
|
||||||
|
@GetMapping("/vehicleManage/findByVehicleVin/{vehicleVin}")
|
||||||
|
// @Operation(description = "通过车辆vin码查询模板id")
|
||||||
|
public Result<Long> findByVehicleVin(@PathVariable("vehicleVin") String vehicleVin);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据报文模版id查询报文数据
|
||||||
|
* @param templateId 请求对象
|
||||||
|
* @return 返回结果
|
||||||
|
*/
|
||||||
|
@GetMapping("/messageValue/findByTemplateId/{templateId}")
|
||||||
|
// @Operation(summary = "根据报文模版id查询报文数据", description = "根据报文模版id查询报文数据")
|
||||||
|
public Result<List<MessageValueListResp>> findByTemplateId(@PathVariable("templateId") Long templateId);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
package com.muyu.analysis.parsing.remote.factory;
|
||||||
|
|
||||||
|
import com.muyu.analysis.parsing.remote.RemoteClientService;
|
||||||
|
import com.muyu.common.core.domain.Result;
|
||||||
|
import com.muyu.enterprise.domain.resp.car.MessageValueListResp;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报文模版对象服务降级处理
|
||||||
|
* @Author:李庆帅
|
||||||
|
* @Package:com.muyu.analysis.parsing.remote.factory
|
||||||
|
* @Project:cloud-server
|
||||||
|
* @name:RemoteServiceClientFactory
|
||||||
|
* @Date:2024/9/28 21:16
|
||||||
|
*/
|
||||||
|
public class RemoteClientServiceFactory implements FallbackFactory<RemoteClientService>
|
||||||
|
{
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(RemoteClientServiceFactory.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RemoteClientService create(Throwable throwable) {
|
||||||
|
log.error("报文模版传参调用失败:{}", throwable.getMessage());
|
||||||
|
return new RemoteClientService(){
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<Long> findByVehicleVin(String vehicleVin) {
|
||||||
|
return Result.error("报文模版传参调用失败" + throwable.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<List<MessageValueListResp>> findByTemplateId(Long templateId) {
|
||||||
|
return Result.error("报文模版传参调用失败" + throwable.getMessage());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.muyu.analysis.parsing.service;
|
||||||
|
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.muyu.enterprise.domain.car.MessageValue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 协议解析业务层
|
||||||
|
* @Author:李庆帅
|
||||||
|
* @Package:com.muyu.analysis.parsing.service
|
||||||
|
* @Project:cloud-server
|
||||||
|
* @name:ParsingService
|
||||||
|
* @Date:2024/9/28 20:50
|
||||||
|
*/
|
||||||
|
public interface ParsingService extends IService<MessageValue>
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 协议解析
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
void mqtt();
|
||||||
|
}
|
|
@ -0,0 +1,151 @@
|
||||||
|
package com.muyu.analysis.parsing.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.muyu.analysis.parsing.controller.ParsingController;
|
||||||
|
import com.muyu.analysis.parsing.remote.RemoteClientService;
|
||||||
|
import com.muyu.analysis.parsing.mapper.ParsingMapper;
|
||||||
|
import com.muyu.analysis.parsing.service.ParsingService;
|
||||||
|
import com.muyu.common.core.domain.Result;
|
||||||
|
import com.muyu.enterprise.domain.car.MessageValue;
|
||||||
|
import com.muyu.enterprise.domain.resp.car.MessageValueListResp;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.eclipse.paho.client.mqttv3.*;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 协议解析实现层
|
||||||
|
* @Author:李庆帅
|
||||||
|
* @Package:com.muyu.analysis.parsing.service.impl
|
||||||
|
* @Project:cloud-server
|
||||||
|
* @name:ParsingServiceImpl
|
||||||
|
* @Date:2024/9/28 20:53
|
||||||
|
*/
|
||||||
|
@Log4j2
|
||||||
|
@Service
|
||||||
|
public class ParsingServiceImpl extends ServiceImpl<ParsingMapper, MessageValue>
|
||||||
|
implements ParsingService
|
||||||
|
{
|
||||||
|
@Resource
|
||||||
|
private RedisTemplate<String, Object> redisTemplate;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RemoteClientService remoteServiceClientService;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mqtt() {
|
||||||
|
String topic = "vehicle";
|
||||||
|
String content = "Message from MqttPublishSample";
|
||||||
|
int qos = 2;
|
||||||
|
String broker = "tcp://106.15.136.7:1883";
|
||||||
|
String clientId = "JavaSample";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 第三个参数为空,默认持久化策略
|
||||||
|
MqttClient sampleClient = new MqttClient(broker, clientId);
|
||||||
|
MqttConnectOptions connOpts = new MqttConnectOptions();
|
||||||
|
connOpts.setCleanSession(true);
|
||||||
|
System.out.println("Connecting to broker: "+broker);
|
||||||
|
sampleClient.connect(connOpts);
|
||||||
|
sampleClient.subscribe(topic,0);
|
||||||
|
sampleClient.setCallback(new MqttCallback() {
|
||||||
|
// 连接丢失
|
||||||
|
@Override
|
||||||
|
public void connectionLost(Throwable throwable) {
|
||||||
|
|
||||||
|
}
|
||||||
|
// 连接成功
|
||||||
|
@Override
|
||||||
|
public void messageArrived(String s, MqttMessage mqttMessage) throws Exception {
|
||||||
|
System.out.println(new String(mqttMessage.getPayload()));
|
||||||
|
String mqtt= new String(mqttMessage.getPayload());
|
||||||
|
JSONObject jsonObject = this.protocolParsing(mqtt);
|
||||||
|
System.out.println("转换后:"+jsonObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONObject protocolParsing(String messageStr) {
|
||||||
|
//根据空格切割数据
|
||||||
|
String[] hexArray = messageStr.split(" ");
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
//遍历十六进制数据转换为字符
|
||||||
|
for (String hex : hexArray) {
|
||||||
|
int decimal = Integer.parseInt(hex, 16);
|
||||||
|
result.append((char) decimal);
|
||||||
|
}
|
||||||
|
//取出车辆VIN码
|
||||||
|
String vehicleVin = result.substring(1, 18);
|
||||||
|
log.info("车辆VIN码: " + vehicleVin);
|
||||||
|
//根据车辆VIN码查询报文模板ID
|
||||||
|
Result<Long> byVehicleVin = remoteServiceClientService.findByVehicleVin(vehicleVin);
|
||||||
|
Long templateId = byVehicleVin.getData();
|
||||||
|
List<MessageValueListResp> templateList;
|
||||||
|
//从redis缓存中获取报文模板数据
|
||||||
|
try {
|
||||||
|
String redisKey = "messageTemplate" + templateId;
|
||||||
|
if (redisTemplate.hasKey(redisKey)) {
|
||||||
|
List<Object> list = redisTemplate.opsForList().range(redisKey, 0, -1);
|
||||||
|
templateList = list.stream()
|
||||||
|
.map(obj -> JSON.parseObject(obj.toString(), MessageValueListResp.class))
|
||||||
|
.toList();
|
||||||
|
log.info("Redis缓存查询成功");
|
||||||
|
} else {
|
||||||
|
Result<List<MessageValueListResp>> byTemplateId = remoteServiceClientService.findByTemplateId(templateId);
|
||||||
|
templateList = byTemplateId.getData();
|
||||||
|
templateList.forEach(
|
||||||
|
listResp ->
|
||||||
|
redisTemplate.opsForList().rightPush(
|
||||||
|
redisKey, JSON.toJSONString(listResp)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
log.info("数据库查询成功");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("获取报文模板失败");
|
||||||
|
}
|
||||||
|
//判断报文模板列表不为空
|
||||||
|
if (templateList.isEmpty()) {
|
||||||
|
throw new RuntimeException("报文模版为空");
|
||||||
|
}
|
||||||
|
//存储报文模版解析后的数据
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
for (MessageValueListResp messageValue : templateList) {
|
||||||
|
//起始位下标
|
||||||
|
Integer startIndex = messageValue.getMessageStartIndex() - 1;
|
||||||
|
//结束位下标
|
||||||
|
Integer endIndex = messageValue.getMessageEndIndex();
|
||||||
|
//根据报文模版截取数据
|
||||||
|
String value = result.substring(startIndex, endIndex);
|
||||||
|
//存入数据
|
||||||
|
jsonObject.put(messageValue.getMessageLabel(), value);
|
||||||
|
}
|
||||||
|
System.out.println("发发呆沙发斯蒂芬萨达:"+jsonObject.toString());
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
// 接收信息
|
||||||
|
@Override
|
||||||
|
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch(MqttException 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
com.muyu.analysis.parsing.remote.factory.RemoteClientServiceFactory
|
|
@ -0,0 +1,2 @@
|
||||||
|
Spring Boot Version: ${spring-boot.version}
|
||||||
|
Spring Application Name: ${spring.application.name}
|
|
@ -0,0 +1,46 @@
|
||||||
|
# Tomcat
|
||||||
|
server:
|
||||||
|
port: 10166
|
||||||
|
|
||||||
|
# nacos线上地址
|
||||||
|
nacos:
|
||||||
|
addr: 106.15.136.7:8848
|
||||||
|
user-name: nacos
|
||||||
|
password: nacos
|
||||||
|
namespace: lqs
|
||||||
|
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
# 应用名称
|
||||||
|
name: cloud-enterprise
|
||||||
|
profiles:
|
||||||
|
# 环境配置
|
||||||
|
active: dev
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
discovery:
|
||||||
|
# 服务注册地址
|
||||||
|
server-addr: ${nacos.addr}
|
||||||
|
# nacos用户名
|
||||||
|
username: ${nacos.user-name}
|
||||||
|
# nacos密码
|
||||||
|
password: ${nacos.password}
|
||||||
|
# 命名空间
|
||||||
|
namespace: ${nacos.namespace}
|
||||||
|
config:
|
||||||
|
# 服务注册地址
|
||||||
|
server-addr: ${nacos.addr}
|
||||||
|
# nacos用户名
|
||||||
|
username: ${nacos.user-name}
|
||||||
|
# nacos密码
|
||||||
|
password: ${nacos.password}
|
||||||
|
# 命名空间
|
||||||
|
namespace: ${nacos.namespace}
|
||||||
|
# 配置文件格式
|
||||||
|
file-extension: yml
|
||||||
|
# 共享配置
|
||||||
|
shared-configs:
|
||||||
|
# 系统共享配置
|
||||||
|
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
|
# 系统环境Config共享配置
|
||||||
|
- application-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
|
@ -0,0 +1,74 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||||
|
<!-- 日志存放路径 -->
|
||||||
|
<property name="log.path" value="logs/cloud-vehicle-gateway"/>
|
||||||
|
<!-- 日志输出格式 -->
|
||||||
|
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||||
|
|
||||||
|
<!-- 控制台输出 -->
|
||||||
|
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>${log.pattern}</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<!-- 系统日志输出 -->
|
||||||
|
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<file>${log.path}/info.log</file>
|
||||||
|
<!-- 循环政策:基于时间创建日志文件 -->
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
|
<!-- 日志文件名格式 -->
|
||||||
|
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||||
|
<!-- 日志最大的历史 60天 -->
|
||||||
|
<maxHistory>60</maxHistory>
|
||||||
|
</rollingPolicy>
|
||||||
|
<encoder>
|
||||||
|
<pattern>${log.pattern}</pattern>
|
||||||
|
</encoder>
|
||||||
|
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||||
|
<!-- 过滤的级别 -->
|
||||||
|
<level>INFO</level>
|
||||||
|
<!-- 匹配时的操作:接收(记录) -->
|
||||||
|
<onMatch>ACCEPT</onMatch>
|
||||||
|
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||||
|
<onMismatch>DENY</onMismatch>
|
||||||
|
</filter>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<file>${log.path}/error.log</file>
|
||||||
|
<!-- 循环政策:基于时间创建日志文件 -->
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
|
<!-- 日志文件名格式 -->
|
||||||
|
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||||
|
<!-- 日志最大的历史 60天 -->
|
||||||
|
<maxHistory>60</maxHistory>
|
||||||
|
</rollingPolicy>
|
||||||
|
<encoder>
|
||||||
|
<pattern>${log.pattern}</pattern>
|
||||||
|
</encoder>
|
||||||
|
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||||
|
<!-- 过滤的级别 -->
|
||||||
|
<level>ERROR</level>
|
||||||
|
<!-- 匹配时的操作:接收(记录) -->
|
||||||
|
<onMatch>ACCEPT</onMatch>
|
||||||
|
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||||
|
<onMismatch>DENY</onMismatch>
|
||||||
|
</filter>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<!-- 系统模块日志级别控制 -->
|
||||||
|
<logger name="com.muyu" level="info"/>
|
||||||
|
<!-- Spring日志级别控制 -->
|
||||||
|
<logger name="org.springframework" level="warn"/>
|
||||||
|
|
||||||
|
<root level="info">
|
||||||
|
<appender-ref ref="console"/>
|
||||||
|
</root>
|
||||||
|
|
||||||
|
<!--系统操作日志-->
|
||||||
|
<root level="info">
|
||||||
|
<appender-ref ref="file_info"/>
|
||||||
|
<appender-ref ref="file_error"/>
|
||||||
|
</root>
|
||||||
|
</configuration>
|
|
@ -0,0 +1,81 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||||
|
<!-- 日志存放路径 -->
|
||||||
|
<property name="log.path" value="logs/cloud-vehicle-gateway"/>
|
||||||
|
<!-- 日志输出格式 -->
|
||||||
|
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||||
|
<property name="log.sky.pattern" value="%d{HH:mm:ss.SSS} %yellow([%tid]) [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||||
|
|
||||||
|
<!-- 控制台输出 -->
|
||||||
|
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>${log.sky.pattern}</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<!-- 系统日志输出 -->
|
||||||
|
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<file>${log.path}/info.log</file>
|
||||||
|
<!-- 循环政策:基于时间创建日志文件 -->
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
|
<!-- 日志文件名格式 -->
|
||||||
|
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||||
|
<!-- 日志最大的历史 60天 -->
|
||||||
|
<maxHistory>60</maxHistory>
|
||||||
|
</rollingPolicy>
|
||||||
|
|
||||||
|
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||||
|
<!-- 过滤的级别 -->
|
||||||
|
<level>INFO</level>
|
||||||
|
<!-- 匹配时的操作:接收(记录) -->
|
||||||
|
<onMatch>ACCEPT</onMatch>
|
||||||
|
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||||
|
<onMismatch>DENY</onMismatch>
|
||||||
|
</filter>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<file>${log.path}/error.log</file>
|
||||||
|
<!-- 循环政策:基于时间创建日志文件 -->
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
|
<!-- 日志文件名格式 -->
|
||||||
|
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||||
|
<!-- 日志最大的历史 60天 -->
|
||||||
|
<maxHistory>60</maxHistory>
|
||||||
|
</rollingPolicy>
|
||||||
|
|
||||||
|
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||||
|
<!-- 过滤的级别 -->
|
||||||
|
<level>ERROR</level>
|
||||||
|
<!-- 匹配时的操作:接收(记录) -->
|
||||||
|
<onMatch>ACCEPT</onMatch>
|
||||||
|
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||||
|
<onMismatch>DENY</onMismatch>
|
||||||
|
</filter>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<!-- 使用gRpc将日志发送到skywalking服务端 -->
|
||||||
|
<appender name="GRPC_LOG" class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.log.GRPCLogClientAppender">
|
||||||
|
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
|
||||||
|
<layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
|
||||||
|
<Pattern>${log.sky.pattern}</Pattern>
|
||||||
|
</layout>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<!-- 系统模块日志级别控制 -->
|
||||||
|
<logger name="com.muyu" level="info"/>
|
||||||
|
<!-- Spring日志级别控制 -->
|
||||||
|
<logger name="org.springframework" level="warn"/>
|
||||||
|
|
||||||
|
<root level="info">
|
||||||
|
<appender-ref ref="GRPC_LOG"/>
|
||||||
|
<appender-ref ref="console"/>
|
||||||
|
</root>
|
||||||
|
|
||||||
|
<!--系统操作日志-->
|
||||||
|
<root level="info">
|
||||||
|
<appender-ref ref="file_info"/>
|
||||||
|
<appender-ref ref="file_error"/>
|
||||||
|
</root>
|
||||||
|
</configuration>
|
|
@ -0,0 +1,81 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||||
|
<!-- 日志存放路径 -->
|
||||||
|
<property name="log.path" value="logs/cloud-vehicle-gateway"/>
|
||||||
|
<!-- 日志输出格式 -->
|
||||||
|
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||||
|
<property name="log.sky.pattern" value="%d{HH:mm:ss.SSS} %yellow([%tid]) [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||||
|
|
||||||
|
<!-- 控制台输出 -->
|
||||||
|
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>${log.sky.pattern}</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<!-- 系统日志输出 -->
|
||||||
|
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<file>${log.path}/info.log</file>
|
||||||
|
<!-- 循环政策:基于时间创建日志文件 -->
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
|
<!-- 日志文件名格式 -->
|
||||||
|
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||||
|
<!-- 日志最大的历史 60天 -->
|
||||||
|
<maxHistory>60</maxHistory>
|
||||||
|
</rollingPolicy>
|
||||||
|
|
||||||
|
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||||
|
<!-- 过滤的级别 -->
|
||||||
|
<level>INFO</level>
|
||||||
|
<!-- 匹配时的操作:接收(记录) -->
|
||||||
|
<onMatch>ACCEPT</onMatch>
|
||||||
|
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||||
|
<onMismatch>DENY</onMismatch>
|
||||||
|
</filter>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<file>${log.path}/error.log</file>
|
||||||
|
<!-- 循环政策:基于时间创建日志文件 -->
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
|
<!-- 日志文件名格式 -->
|
||||||
|
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||||
|
<!-- 日志最大的历史 60天 -->
|
||||||
|
<maxHistory>60</maxHistory>
|
||||||
|
</rollingPolicy>
|
||||||
|
|
||||||
|
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||||
|
<!-- 过滤的级别 -->
|
||||||
|
<level>ERROR</level>
|
||||||
|
<!-- 匹配时的操作:接收(记录) -->
|
||||||
|
<onMatch>ACCEPT</onMatch>
|
||||||
|
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||||
|
<onMismatch>DENY</onMismatch>
|
||||||
|
</filter>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<!-- 使用gRpc将日志发送到skywalking服务端 -->
|
||||||
|
<appender name="GRPC_LOG" class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.log.GRPCLogClientAppender">
|
||||||
|
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
|
||||||
|
<layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
|
||||||
|
<Pattern>${log.sky.pattern}</Pattern>
|
||||||
|
</layout>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<!-- 系统模块日志级别控制 -->
|
||||||
|
<logger name="com.muyu" level="info"/>
|
||||||
|
<!-- Spring日志级别控制 -->
|
||||||
|
<logger name="org.springframework" level="warn"/>
|
||||||
|
|
||||||
|
<root level="info">
|
||||||
|
<appender-ref ref="GRPC_LOG"/>
|
||||||
|
<appender-ref ref="console"/>
|
||||||
|
</root>
|
||||||
|
|
||||||
|
<!--系统操作日志-->
|
||||||
|
<root level="info">
|
||||||
|
<appender-ref ref="file_info"/>
|
||||||
|
<appender-ref ref="file_error"/>
|
||||||
|
</root>
|
||||||
|
</configuration>
|
|
@ -15,6 +15,7 @@
|
||||||
<modules>
|
<modules>
|
||||||
<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-protocol-analysis</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
|
|
Loading…
Reference in New Issue