Compare commits
32 Commits
8e0e492555
...
82ec79ccaf
Author | SHA1 | Date |
---|---|---|
|
82ec79ccaf | |
|
551f5f5496 | |
|
f93af8b4a6 | |
|
1272d0e0b7 | |
|
1f072d4ca2 | |
|
8de7f88912 | |
|
ddf4ede829 | |
|
83ab8a27a7 | |
|
d38d77b331 | |
|
bc3053d834 | |
|
4ecdbe3881 | |
|
d586c26468 | |
|
7b36e4b359 | |
|
29cb1ffadb | |
|
2488248967 | |
|
dea0f07c90 | |
|
7d7950e925 | |
|
e3f65e7f1e | |
|
f4faf4d828 | |
|
a0994c3e7a | |
|
0228051467 | |
|
688154709d | |
|
c35dea9159 | |
|
3f9a930c95 | |
|
030f16e6a8 | |
|
3aab1823a1 | |
|
6079949a7a | |
|
cd0d2e4475 | |
|
e716ad9bfc | |
|
71083dc580 | |
|
52453e089b | |
|
9747b41b34 |
|
@ -0,0 +1,24 @@
|
|||
package com.muyu.auth.form;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 企业入驻对象
|
||||
* @author 袁子龙
|
||||
* @package com.muyu.auth.form
|
||||
* @name Enterprise
|
||||
* @date 2024/9/30 10:30
|
||||
*/
|
||||
@Data
|
||||
public class Enterprise {
|
||||
|
||||
/**
|
||||
* 企业名称
|
||||
*/
|
||||
private String firmName;
|
||||
/**
|
||||
* 数据库名称
|
||||
*/
|
||||
private String databaseName;
|
||||
|
||||
}
|
|
@ -7,7 +7,7 @@ nacos:
|
|||
addr: 47.101.53.251:8848
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: four
|
||||
namespace: yzl
|
||||
# Spring
|
||||
spring:
|
||||
application:
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
<?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>
|
||||
|
||||
<groupId>com.muyu.cache</groupId>
|
||||
<artifactId>cloud-common-cache</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>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-redis</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,38 @@
|
|||
package com.muyu.cache;/**
|
||||
* @author yuping
|
||||
* @package com.muyu.cache
|
||||
* @name CacheAbsBasic
|
||||
* @date 2024/9/29 20:10 抽象缓存层
|
||||
*/
|
||||
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import static cn.hutool.core.lang.ansi.AnsiEncoder.encode;
|
||||
|
||||
/**
|
||||
* @Author YuPing
|
||||
* @Description
|
||||
* @Version 1.0
|
||||
* @Data 2024-09-29 20:10:09
|
||||
*/
|
||||
public abstract class CacheAbsBasic<K,V> implements CacheBasic<K,V>{
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService; // spring redis 工具类
|
||||
|
||||
@Override
|
||||
public void put(K key, V value) {
|
||||
redisService.setCacheObject(encodeKey(key), value); // 编码 --> 缓存基础的对象 Integer String 实体类等
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get(K key) {
|
||||
return redisService.getCacheObject(encode(key)); // 获取缓存的基本对象 编码
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(K key) {
|
||||
redisService.deleteObject(encode(key));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.muyu.cache;
|
||||
|
||||
/**
|
||||
* @author yuping
|
||||
* @package com.muyu.cache
|
||||
* @name CacheBasic
|
||||
* @date 2024/9/29 20:08 缓存基础
|
||||
*/
|
||||
public interface CacheBasic <K,V> extends PrimaryKeyBasic<K>{
|
||||
|
||||
void put(K key, V value);
|
||||
|
||||
V get(K key);
|
||||
|
||||
void remove(K key);
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package com.muyu.cache;
|
||||
|
||||
/**
|
||||
* @author yuping
|
||||
* @package com.muyu.cache
|
||||
* @name PrimaryKeyBasic
|
||||
* @date 2024/9/29 20:03 主键基础
|
||||
*/
|
||||
public interface PrimaryKeyBasic <K> {
|
||||
|
||||
/**
|
||||
* key 前缀
|
||||
* @return key前缀
|
||||
*/
|
||||
public String keyPre();
|
||||
|
||||
|
||||
/**
|
||||
* key 编码
|
||||
* @param key 缓存键
|
||||
* @return 封装键
|
||||
*/
|
||||
public default String encodeKey(K key) {
|
||||
return keyPre() + key.toString(); //key 前缀
|
||||
}
|
||||
|
||||
/**
|
||||
* 解码 key
|
||||
* @param key 编码key
|
||||
* @return 解码后的key
|
||||
*/
|
||||
public K decode(String key);
|
||||
|
||||
}
|
|
@ -138,10 +138,10 @@
|
|||
</dependency>
|
||||
|
||||
<!-- Java Specification Requests 标准库-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>javax.annotation</groupId>-->
|
||||
<!-- <artifactId>jsr250-api</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>javax.annotation</groupId>-->
|
||||
<!-- <artifactId>jsr250-api</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.annotation</groupId>
|
||||
|
|
|
@ -5,21 +5,21 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-server</artifactId>
|
||||
<artifactId>cloud-common</artifactId>
|
||||
<version>3.6.3</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<groupId>com.muyu</groupId>
|
||||
<groupId>com.bwie</groupId>
|
||||
<artifactId>cloud-common-swagger</artifactId>
|
||||
<description>
|
||||
cloud-common-swagger swagger2文档聚合
|
||||
cloud-common-swagger系统接口
|
||||
</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>
|
||||
<!-- SpringBoot Web -->
|
||||
<dependency>
|
||||
|
|
|
@ -1,10 +1,21 @@
|
|||
package com.muyu.common.swagger.annotation;
|
||||
|
||||
import com.muyu.common.swagger.config.SwaggerAutoConfiguration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* @author 袁子龙
|
||||
* @package:com.muyu.common.swagger.annotation
|
||||
* @name:EnableCustomSwagger2
|
||||
* @date:2024/9/29 10:01
|
||||
*/
|
||||
@Target({ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Inherited
|
||||
@Import({SwaggerAutoConfiguration.class})
|
||||
public @interface EnableCustomSwagger2 {
|
||||
|
||||
}
|
||||
|
|
|
@ -22,9 +22,9 @@ import java.util.function.Predicate;
|
|||
|
||||
/**
|
||||
* @author 袁子龙
|
||||
* @package:com.muyu.common.swagger.config
|
||||
* @name:SwaggerAutoConfiguration
|
||||
* @date:2024/9/29 10:07
|
||||
* @package com.muyu.common.swagger.config
|
||||
* @name SwaggerAutoConfiguration
|
||||
* @date 2024/9/29 10:07
|
||||
*/
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
|
|
|
@ -12,6 +12,7 @@ import java.util.List;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 在 springboot 2.6.x 不兼容问题的处理
|
||||
* @author 袁子龙
|
||||
* @package:com.muyu.common.swagger.config
|
||||
* @name:SwaggerBeanPostProcessor
|
||||
|
|
|
@ -300,4 +300,3 @@ public class SwaggerProperties {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
<module>cloud-common-rabbit</module>
|
||||
<module>cloud-common-saas</module>
|
||||
<module>cloud-common-swagger</module>
|
||||
<module>cloud-common-cache</module>
|
||||
</modules>
|
||||
|
||||
<artifactId>cloud-common</artifactId>
|
||||
|
|
|
@ -7,7 +7,7 @@ nacos:
|
|||
addr: 47.101.53.251:8848
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: four
|
||||
namespace: yzl
|
||||
|
||||
# Spring
|
||||
spring:
|
||||
|
|
|
@ -6,7 +6,7 @@ nacos:
|
|||
addr: 47.101.53.251:8848
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: four
|
||||
namespace: yzl
|
||||
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
|
||||
# Spring
|
||||
amqp:
|
||||
|
|
|
@ -7,7 +7,7 @@ nacos:
|
|||
addr: 47.101.53.251:8848
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: four
|
||||
namespace: yzl
|
||||
|
||||
# Spring
|
||||
spring:
|
||||
|
|
|
@ -9,7 +9,7 @@ import org.springframework.stereotype.Service;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 业务字段 服务层实现
|
||||
* 业务字段 业务逻辑层实现
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
|
|
|
@ -40,7 +40,7 @@ import java.util.zip.ZipEntry;
|
|||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
/**
|
||||
* 业务 服务层实现
|
||||
* 业务 业务逻辑层实现
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
|
|
|
@ -7,7 +7,7 @@ nacos:
|
|||
addr: 47.101.53.251:8848
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: four
|
||||
namespace: yzl
|
||||
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
|
||||
# Spring
|
||||
spring:
|
||||
|
|
|
@ -7,7 +7,7 @@ import com.muyu.system.domain.vo.TreeSelect;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 部门管理 服务层
|
||||
* 部门管理 业务逻辑层
|
||||
*
|
||||
* @author muyu
|
||||
*/
|
||||
|
|
|
@ -7,7 +7,7 @@ nacos:
|
|||
addr: 47.101.53.251:8848
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: four
|
||||
namespace: yzl
|
||||
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
|
||||
# Spring
|
||||
spring:
|
||||
|
|
|
@ -102,6 +102,36 @@
|
|||
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
|
||||
<version>1.2.5</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>ecs20140526</artifactId>
|
||||
<version>5.1.8</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>tea-openapi</artifactId>
|
||||
<version>0.3.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>tea-console</artifactId>
|
||||
<version>0.0.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>tea-util</artifactId>
|
||||
<version>0.2.21</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>aliyun-java-sdk-ecs</artifactId>
|
||||
<version>4.2.0</version><!-- 请根据实际情况使用最新的版本 -->
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -0,0 +1,173 @@
|
|||
package com.muyu.vehicle;
|
||||
|
||||
|
||||
import com.aliyun.ecs20140526.Client;
|
||||
import com.aliyun.ecs20140526.models.*;
|
||||
import com.aliyun.tea.TeaException;
|
||||
import com.aliyun.teaopenapi.models.Config;
|
||||
import com.aliyun.teautil.Common;
|
||||
import com.aliyun.teautil.models.RuntimeOptions;
|
||||
import com.muyu.vehicle.domain.InstanceInfo;
|
||||
import com.muyu.vehicle.service.OpenInstance;
|
||||
import com.muyu.vehicle.service.SelectInstance;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@Log4j2
|
||||
public class ManageInstance implements ApplicationRunner {
|
||||
|
||||
/**
|
||||
* ACCESS_KEY_ID
|
||||
*/
|
||||
public static final String ALIBABA_CLOUD_ACCESS_KEY_ID="LTAI5tGabdxedjfCh2uXHNrw";
|
||||
|
||||
/**
|
||||
*ACCESS_KEY_SECRET
|
||||
*/
|
||||
public static final String ACCESS_KEY_SECRET="NHb7wHVpesLW6Axc0bFBs6ThhuNR10";
|
||||
|
||||
|
||||
/**
|
||||
* 镜像ID
|
||||
*/
|
||||
public static final String IMAGE_ID="m-uf6agr9i6g27gj23om34";
|
||||
|
||||
/**
|
||||
* 实例类型
|
||||
*/
|
||||
public static final String INSTANCE_TYPE="ecs.e-c1m1.large";
|
||||
|
||||
/**
|
||||
* 安全组ID
|
||||
*/
|
||||
public static final String SECURITY_GROUP_ID="sg-uf6glo8c4k17szhxu7sk";
|
||||
|
||||
/**
|
||||
*交换机ID
|
||||
*/
|
||||
public static final String V_SWITCH_ID="vsw-uf6xy4rbt9ggcz93t6oib";
|
||||
|
||||
|
||||
/**
|
||||
* 实例付费类型
|
||||
*/
|
||||
public static final String INSTANCE_CHARGE_TY="PostPaid";
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 使用AK&SK初始化账号Client
|
||||
* @return Client
|
||||
* @throws Exception
|
||||
*/
|
||||
|
||||
public static Client createClient() throws Exception {
|
||||
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
|
||||
Config config = new Config()
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
|
||||
.setAccessKeyId(ALIBABA_CLOUD_ACCESS_KEY_ID)
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
|
||||
.setAccessKeySecret(ACCESS_KEY_SECRET);
|
||||
// Endpoint 请参考 https://api.aliyun.com/product/Ecs
|
||||
config.endpoint = "ecs-cn-hangzhou.aliyuncs.com";
|
||||
return new com.aliyun.ecs20140526.Client(config);
|
||||
}
|
||||
|
||||
|
||||
public static void generateInstance() throws Exception {
|
||||
// 创建阿里云ECS客户端
|
||||
Client client = ManageInstance.createClient();
|
||||
// 配置系统盘参数
|
||||
RunInstancesRequest.RunInstancesRequestSystemDisk systemDisk=
|
||||
new RunInstancesRequest.RunInstancesRequestSystemDisk()
|
||||
.setSize("40")
|
||||
.setCategory("cloud_essd");
|
||||
|
||||
// 创建创建实例请求对象并设置参数
|
||||
|
||||
RunInstancesRequest runInstancesRequest = new RunInstancesRequest()
|
||||
.setRegionId("cn-shanghai") // 设置地域ID
|
||||
.setImageId(IMAGE_ID) // 设置镜像ID
|
||||
.setInstanceType(INSTANCE_TYPE) // 设置实例类型
|
||||
.setSecurityGroupId(SECURITY_GROUP_ID) // 设置安全组ID
|
||||
.setVSwitchId(V_SWITCH_ID) // 设置虚拟交换机ID
|
||||
.setInstanceName("cloud-MQTT") // 设置实例名称
|
||||
.setInstanceChargeType(INSTANCE_CHARGE_TY) // 设置实例付费类型为后付费按量付费
|
||||
.setSystemDisk(systemDisk) // 设置系统盘配置
|
||||
.setHostName("root") // 设置主机名
|
||||
.setPassword("2112A-four") // 设置实例密码
|
||||
.setAmount(2) // 设置创建实例的数量
|
||||
.setInternetChargeType("PayByTraffic")
|
||||
.setInternetMaxBandwidthOut(1);
|
||||
|
||||
|
||||
//创建运行时选择对象
|
||||
RuntimeOptions runTime=
|
||||
new RuntimeOptions();
|
||||
// 尝试执行创建实例请求
|
||||
try {
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
// 复制代码运行请自行打印 API 的返回值
|
||||
RunInstancesResponse runInstancesResponse = client.runInstancesWithOptions(runInstancesRequest, runTime);
|
||||
RunInstancesResponseBody body = runInstancesResponse.getBody();
|
||||
for (String instance : body.getInstanceIdSets().getInstanceIdSet()) {
|
||||
list.add(instance);
|
||||
}
|
||||
log.info("ESC创建成功,实例ID为:" + list);
|
||||
} catch (TeaException error) {
|
||||
// 错误 message
|
||||
log.info(error.getMessage());
|
||||
// 诊断地址
|
||||
log.info(error.getData().get("Recommend"));
|
||||
Common.assertAsString(error.message);
|
||||
} catch (Exception _error) {
|
||||
TeaException error = new TeaException(_error.getMessage(), _error);
|
||||
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
||||
// 错误 message
|
||||
log.info("实例创建失败:"+error.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static List<InstanceInfo> selectInstance() throws Exception {
|
||||
Client client = ManageInstance.createClient();
|
||||
ArrayList<InstanceInfo> instanceInfos = new ArrayList<>();// 实例基础信息
|
||||
DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest()
|
||||
.setRegionId("cn-shanghai")
|
||||
.setInternetChargeType("PayByTraffic")
|
||||
.setInstanceChargeType("PostPaid")
|
||||
.setInstanceName("cloud-MQTT") // 设置实例名称
|
||||
;
|
||||
// 创建运行时选项对象
|
||||
RuntimeOptions runtime = new RuntimeOptions();
|
||||
//实例ID Instances.Instance.InstanceId
|
||||
//实例IP Instances.Instance.PublicIpAddress.IpAddress
|
||||
//状态 Instances.Instance.Status
|
||||
DescribeInstancesResponse resp =client.describeInstancesWithOptions(describeInstancesRequest, runtime);
|
||||
DescribeInstancesResponseBody body = resp.getBody();
|
||||
|
||||
for (DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance instance : body.getInstances().getInstance()){
|
||||
InstanceInfo instanceInfo = new InstanceInfo();
|
||||
instanceInfo.setInstanceId(instance.getInstanceId());
|
||||
instanceInfo.setIpAddress(String.valueOf(instance.getPublicIpAddress().getIpAddress()));
|
||||
instanceInfo.setStatus(instance.getStatus());
|
||||
instanceInfos.add(instanceInfo);
|
||||
|
||||
}
|
||||
log.info("实例信息为:"+Common.toJSONString(instanceInfos));
|
||||
return instanceInfos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
generateInstance();
|
||||
selectInstance();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,132 +0,0 @@
|
|||
package com.muyu.vehicle;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.muyu.web.common.ScheduledThreadPool;
|
||||
import com.muyu.web.domain.MqttProperties;
|
||||
import com.muyu.web.domain.VehicleInfo;
|
||||
import com.muyu.web.domain.model.PositionModel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.eclipse.paho.client.mqttv3.MqttClient;
|
||||
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
|
||||
import org.eclipse.paho.client.mqttv3.MqttException;
|
||||
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@Log4j2
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class VehicleInstance {
|
||||
/**
|
||||
* 路线轨迹编码
|
||||
*/
|
||||
private String positionCode;
|
||||
|
||||
/**
|
||||
* 路径队列
|
||||
*/
|
||||
private LinkedBlockingQueue<PositionModel> positionQueue=new LinkedBlockingQueue<>();
|
||||
|
||||
/**
|
||||
* 车辆
|
||||
*/
|
||||
private VehicleInfo vehicleInfo;
|
||||
|
||||
/**
|
||||
* 车辆工作线程
|
||||
*/
|
||||
private VehicleThread vehicleThread;
|
||||
|
||||
/**
|
||||
* MQTT配置
|
||||
*/
|
||||
private MqttProperties mqttProperties;
|
||||
|
||||
/**
|
||||
* 线程提交回调
|
||||
*/
|
||||
private ScheduledFuture<?>scheduledFuture;
|
||||
|
||||
/**
|
||||
* 连接上报
|
||||
*/
|
||||
private MqttClient client;
|
||||
|
||||
|
||||
/**
|
||||
* 获取当前车辆VIN
|
||||
*/
|
||||
public String getVin(){
|
||||
return this.vehicleInfo.getVin();
|
||||
}
|
||||
/**
|
||||
* 获取车辆租户信息
|
||||
*/
|
||||
public String getTenantId(){
|
||||
return this.vehicleInfo.getTenantId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送消息
|
||||
*/
|
||||
public void sengMsg(String msg){
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 初始化客户端
|
||||
*/
|
||||
public void initClient(){
|
||||
try {
|
||||
client = new MqttClient(mqttProperties.getBroker(), mqttProperties.getClientId(), new MemoryPersistence());
|
||||
MqttConnectOptions options = new MqttConnectOptions();
|
||||
//设置用户名和密码
|
||||
if (Objects.nonNull(mqttProperties.getUserName())&&Objects.nonNull(mqttProperties.getPassword())){
|
||||
options.setUserName(mqttProperties.getUserName());
|
||||
options.setPassword(mqttProperties.getPassword().toCharArray());
|
||||
}
|
||||
options.setConnectionTimeout(1);
|
||||
options.setKeepAliveInterval(20);
|
||||
//连接
|
||||
client.connect(options);
|
||||
log.debug("车辆:[{}]客户端初始化成功连接配置:{}",getVin(),
|
||||
JSONObject.toJSONString(this.mqttProperties)
|
||||
);
|
||||
VehicleThread vehicleThread = new VehicleThread();
|
||||
vehicleThread.setVehicleInstance(this);
|
||||
this.setVehicleThread(vehicleThread);
|
||||
ScheduledFuture<?> submit = ScheduledThreadPool.submit(vehicleThread);
|
||||
this.setScheduledFuture(submit);
|
||||
log.info("初始化车辆上报模拟线程开始:[{}]", this.getVin());
|
||||
} catch (MqttException e) {
|
||||
log.error("车辆:[{}] 客户端初始化异常", getVin(), e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否连接在线
|
||||
*/
|
||||
public boolean isOnline(){
|
||||
if (this.client==null){
|
||||
return false;
|
||||
}
|
||||
return this.client.isConnected();
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否建立车辆模拟线程
|
||||
*/
|
||||
public boolean isSend(){
|
||||
return this.vehicleThread!=null;
|
||||
}
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
package com.muyu.vehicle;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
||||
@Data
|
||||
@Log4j2
|
||||
public class VehicleThread implements Runnable{
|
||||
/**
|
||||
* 是否停止线程
|
||||
*/
|
||||
private volatile boolean isStop;
|
||||
|
||||
/**
|
||||
* 车辆实例对象
|
||||
*/
|
||||
private VehicleInstance vehicleInstance;
|
||||
@Override
|
||||
public void run() {
|
||||
if (!isStop){
|
||||
log.info("{}-上报数据",this.vehicleInstance.getVin());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
package com.muyu.vehicle.api;
|
||||
|
||||
/**
|
||||
* 客户端管理
|
||||
*/
|
||||
public interface ClientAdmin {
|
||||
/**
|
||||
* 获取车辆负载地址
|
||||
*/
|
||||
|
||||
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
package com.muyu.vehicle.core;
|
||||
|
||||
import com.muyu.vehicle.VehicleInstance;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class LocalContainer {
|
||||
private static final Map<String,Map<String, VehicleInstance>> tenantVehicleDataMap
|
||||
=new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* 获取租户ID下车辆
|
||||
*/
|
||||
public static Map<String,VehicleInstance>getVehicleDataMap(String tenantId){
|
||||
return tenantVehicleDataMap.computeIfAbsent(tenantId,k->new ConcurrentHashMap<>());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package com.muyu.vehicle.core;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Log4j2
|
||||
@Configuration
|
||||
@AllArgsConstructor
|
||||
public class VehicleConfiguration {
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.muyu.vehicle.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class InstanceInfo {
|
||||
|
||||
//实例ID
|
||||
private String InstanceId;
|
||||
|
||||
private String IpAddress;
|
||||
|
||||
private String status;
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
package com.muyu.vehicle.service;
|
||||
|
||||
|
||||
import com.aliyun.ecs20140526.Client;
|
||||
import com.aliyun.ecs20140526.models.DeleteInstancesRequest;
|
||||
import com.aliyun.ecs20140526.models.DescribeInstancesRequest;
|
||||
import com.aliyun.ecs20140526.models.DescribeInstancesResponse;
|
||||
import com.aliyun.ecs20140526.models.DescribeInstancesResponseBody;
|
||||
import com.aliyun.tea.TeaException;
|
||||
import com.aliyun.teaopenapi.models.Config;
|
||||
import com.aliyun.teautil.Common;
|
||||
import com.aliyun.teautil.models.RuntimeOptions;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
@Component
|
||||
@Log4j2
|
||||
public class CloseInstance implements DisposableBean {
|
||||
/**
|
||||
* ACCESS_KEY_ID
|
||||
*/
|
||||
public static final String ALIBABA_CLOUD_ACCESS_KEY_ID="LTAI5tGabdxedjfCh2uXHNrw";
|
||||
|
||||
/**
|
||||
*ACCESS_KEY_SECRET
|
||||
*/
|
||||
public static final String ACCESS_KEY_SECRET="NHb7wHVpesLW6Axc0bFBs6ThhuNR10";
|
||||
public static Client createClient() throws Exception {
|
||||
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
|
||||
// 建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378657.html。
|
||||
Config config = new Config()
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
|
||||
.setAccessKeyId(ALIBABA_CLOUD_ACCESS_KEY_ID)
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
|
||||
.setAccessKeySecret(ACCESS_KEY_SECRET);
|
||||
// Endpoint 请参考 https://api.aliyun.com/product/Ecs
|
||||
config.endpoint = "ecs.cn-shanghai.aliyuncs.com";
|
||||
return new Client(config);
|
||||
}
|
||||
|
||||
public static void delInstance() throws Exception {
|
||||
|
||||
// 创建ECS客户端对象,用于后续调用ECS相关API
|
||||
Client client = CloseInstance.createClient();
|
||||
|
||||
DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest()
|
||||
.setRegionId("cn-shanghai");
|
||||
|
||||
//创建运行时选择对象,用于配置运行时的选项参数
|
||||
RuntimeOptions runtimeOptions = new RuntimeOptions();
|
||||
|
||||
//获取实例列表
|
||||
DescribeInstancesResponse describeInstancesResponse = client.describeInstancesWithOptions(describeInstancesRequest, runtimeOptions);
|
||||
|
||||
//提取实例ID集合
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
DescribeInstancesResponseBody body = describeInstancesResponse.getBody();
|
||||
|
||||
for (DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance instance : body.getInstances().getInstance()) {
|
||||
if (!instance.getInstanceId().equals("i-uf68jwsbbqq4b4xc893s")){
|
||||
list.add(instance.getInstanceId());
|
||||
}
|
||||
}
|
||||
log.info("搜索到实例Instance IDs: " + list);
|
||||
// 创建删除实例请求对象,并设置请求参数
|
||||
DeleteInstancesRequest deleteInstancesRequest = new DeleteInstancesRequest()
|
||||
// 设置地域ID,指定删除实例的地域
|
||||
.setRegionId("cn-shanghai")
|
||||
// 设置DryRun为true,用于验证请求是否可以成功,但不实际执行删除操作
|
||||
.setDryRun(false)
|
||||
// 设置Force为true,表示即使实例有正在运行的任务,也强制删除实例
|
||||
.setForce(true)
|
||||
// 设置TerminateSubscription为true,表示删除按订阅付费的实例时终止订阅
|
||||
.setTerminateSubscription(true)
|
||||
.setInstanceId(list);
|
||||
|
||||
// 创建运行时选项对象,用于配置运行时的选项参数
|
||||
RuntimeOptions runtime = new RuntimeOptions();
|
||||
try {
|
||||
// 复制代码运行请自行打印 API 的返回值
|
||||
client.deleteInstancesWithOptions(deleteInstancesRequest, runtime);
|
||||
} catch (TeaException error) {
|
||||
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
||||
// 错误 message
|
||||
log.info(error.getMessage());
|
||||
// 诊断地址
|
||||
log.info(error.getData().get("Recommend"));
|
||||
Common.assertAsString(error.message);
|
||||
} catch (Exception _error) {
|
||||
TeaException error = new TeaException(_error.getMessage(), _error);
|
||||
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
||||
// 错误 message
|
||||
System.out.println(error.getMessage());
|
||||
// 诊断地址
|
||||
log.info(error.getData().get("Recommend"));
|
||||
Common.assertAsString(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void destroy() throws Exception {
|
||||
log.info("开始删除实例");
|
||||
delInstance();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,129 @@
|
|||
package com.muyu.vehicle.service;
|
||||
|
||||
import com.aliyun.ecs20140526.Client;
|
||||
import com.aliyun.ecs20140526.models.RunInstancesRequest;
|
||||
import com.aliyun.ecs20140526.models.RunInstancesResponse;
|
||||
import com.aliyun.ecs20140526.models.RunInstancesResponseBody;
|
||||
import com.aliyun.tea.TeaException;
|
||||
import com.aliyun.teaopenapi.models.Config;
|
||||
import com.aliyun.teautil.Common;
|
||||
import com.aliyun.teautil.models.RuntimeOptions;
|
||||
import com.muyu.vehicle.ManageInstance;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Log4j2
|
||||
public class OpenInstance {
|
||||
/**
|
||||
* ACCESS_KEY_ID
|
||||
*/
|
||||
public static final String ALIBABA_CLOUD_ACCESS_KEY_ID="LTAI5tGabdxedjfCh2uXHNrw";
|
||||
|
||||
/**
|
||||
*ACCESS_KEY_SECRET
|
||||
*/
|
||||
public static final String ACCESS_KEY_SECRET="NHb7wHVpesLW6Axc0bFBs6ThhuNR10";
|
||||
|
||||
|
||||
/**
|
||||
* 镜像ID
|
||||
*/
|
||||
public static final String IMAGE_ID="m-uf6agr9i6g27gj23om34";
|
||||
|
||||
/**
|
||||
* 实例类型
|
||||
*/
|
||||
public static final String INSTANCE_TYPE="ecs.e-c1m1.large";
|
||||
|
||||
/**
|
||||
* 安全组ID
|
||||
*/
|
||||
public static final String SECURITY_GROUP_ID="sg-uf6glo8c4k17szhxu7sk";
|
||||
|
||||
/**
|
||||
*交换机ID
|
||||
*/
|
||||
public static final String V_SWITCH_ID="vsw-uf6xy4rbt9ggcz93t6oib";
|
||||
|
||||
|
||||
/**
|
||||
* 实例付费类型
|
||||
*/
|
||||
public static final String INSTANCE_CHARGE_TY="PostPaid";
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 使用AK&SK初始化账号Client
|
||||
* @return Client
|
||||
* @throws Exception
|
||||
*/
|
||||
|
||||
public static Client createClient() throws Exception {
|
||||
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
|
||||
Config config = new Config()
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
|
||||
.setAccessKeyId(ALIBABA_CLOUD_ACCESS_KEY_ID)
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
|
||||
.setAccessKeySecret(ACCESS_KEY_SECRET);
|
||||
// Endpoint 请参考 https://api.aliyun.com/product/Ecs
|
||||
config.endpoint = "ecs-cn-hangzhou.aliyuncs.com";
|
||||
return new com.aliyun.ecs20140526.Client(config);
|
||||
}
|
||||
|
||||
|
||||
public static void generateInstance() throws Exception {
|
||||
// 创建阿里云ECS客户端
|
||||
Client client = OpenInstance.createClient();
|
||||
// 配置系统盘参数
|
||||
RunInstancesRequest.RunInstancesRequestSystemDisk systemDisk=
|
||||
new RunInstancesRequest.RunInstancesRequestSystemDisk()
|
||||
.setSize("40")
|
||||
.setCategory("cloud_essd");
|
||||
|
||||
// 创建创建实例请求对象并设置参数
|
||||
|
||||
RunInstancesRequest runInstancesRequest = new RunInstancesRequest()
|
||||
.setRegionId("cn-shanghai") // 设置地域ID
|
||||
.setImageId(IMAGE_ID) // 设置镜像ID
|
||||
.setInstanceType(INSTANCE_TYPE) // 设置实例类型
|
||||
.setSecurityGroupId(SECURITY_GROUP_ID) // 设置安全组ID
|
||||
.setVSwitchId(V_SWITCH_ID) // 设置虚拟交换机ID
|
||||
.setInstanceName("cloud-MQTT") // 设置实例名称
|
||||
.setInstanceChargeType(INSTANCE_CHARGE_TY) // 设置实例付费类型为后付费按量付费
|
||||
.setSystemDisk(systemDisk) // 设置系统盘配置
|
||||
.setHostName("root") // 设置主机名
|
||||
.setPassword("2112A-four") // 设置实例密码
|
||||
.setAmount(2) // 设置创建实例的数量
|
||||
.setInternetChargeType("PayByTraffic")
|
||||
.setInternetMaxBandwidthOut(1);
|
||||
|
||||
|
||||
//创建运行时选择对象
|
||||
RuntimeOptions runTime=
|
||||
new RuntimeOptions();
|
||||
// 尝试执行创建实例请求
|
||||
try {
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
// 复制代码运行请自行打印 API 的返回值
|
||||
RunInstancesResponse runInstancesResponse = client.runInstancesWithOptions(runInstancesRequest, runTime);
|
||||
RunInstancesResponseBody body = runInstancesResponse.getBody();
|
||||
for (String instance : body.getInstanceIdSets().getInstanceIdSet()) {
|
||||
list.add(instance);
|
||||
log.info("ESC创建成功,实例ID为:" + list);
|
||||
}
|
||||
} catch (TeaException error) {
|
||||
// 错误 message
|
||||
log.info(error.getMessage());
|
||||
// 诊断地址
|
||||
log.info(error.getData().get("Recommend"));
|
||||
Common.assertAsString(error.message);
|
||||
} catch (Exception _error) {
|
||||
TeaException error = new TeaException(_error.getMessage(), _error);
|
||||
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
||||
// 错误 message
|
||||
log.info("实例创建失败:"+error.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package com.muyu.vehicle.service;
|
||||
|
||||
import com.aliyun.ecs20140526.Client;
|
||||
import com.aliyun.ecs20140526.models.DescribeInstancesRequest;
|
||||
import com.aliyun.ecs20140526.models.DescribeInstancesResponse;
|
||||
import com.aliyun.ecs20140526.models.DescribeInstancesResponseBody;
|
||||
import com.aliyun.teaopenapi.models.Config;
|
||||
import com.aliyun.teautil.Common;
|
||||
import com.aliyun.teautil.models.RuntimeOptions;
|
||||
import com.muyu.vehicle.domain.InstanceInfo;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Log4j2
|
||||
public class SelectInstance {
|
||||
/**
|
||||
* ACCESS_KEY_ID
|
||||
*/
|
||||
public static final String ALIBABA_CLOUD_ACCESS_KEY_ID="LTAI5tGabdxedjfCh2uXHNrw";
|
||||
|
||||
/**
|
||||
*ACCESS_KEY_SECRET
|
||||
*/
|
||||
public static final String ACCESS_KEY_SECRET="NHb7wHVpesLW6Axc0bFBs6ThhuNR10";
|
||||
|
||||
public static Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
|
||||
Config config = new com.aliyun.teaopenapi.models.Config()
|
||||
// 必填,您的 AccessKey ID
|
||||
.setAccessKeyId(ALIBABA_CLOUD_ACCESS_KEY_ID)
|
||||
// 必填,您的 AccessKey Secret
|
||||
.setAccessKeySecret(ACCESS_KEY_SECRET);
|
||||
// 访问的域名
|
||||
config.endpoint = "ecs-cn-hangzhou.aliyuncs.com";
|
||||
return new Client(config);
|
||||
}
|
||||
|
||||
public static void main(String[] args_) throws Exception {
|
||||
java.util.List<String> args = java.util.Arrays.asList(args_);
|
||||
// 请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID 和 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
|
||||
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考,建议使用更安全的 STS 方式
|
||||
Client client = SelectInstance.createClient(ALIBABA_CLOUD_ACCESS_KEY_ID, ACCESS_KEY_SECRET);
|
||||
DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest()
|
||||
.setRegionId("cn-shanghai")
|
||||
.setInternetChargeType("PayByTraffic")
|
||||
.setInstanceChargeType("PostPaid")
|
||||
.setInstanceName("cloud-MQTT") // 设置实例名称
|
||||
;
|
||||
//实例ID Instances.Instance.InstanceId
|
||||
//实例IP Instances.Instance.PublicIpAddress.IpAddress
|
||||
//状态 Instances.Instance.Status
|
||||
RuntimeOptions runtime = new RuntimeOptions();
|
||||
DescribeInstancesResponse resp = client.describeInstancesWithOptions(describeInstancesRequest, runtime);
|
||||
DescribeInstancesResponseBody body = resp.getBody();
|
||||
ArrayList<InstanceInfo> instanceInfos = new ArrayList<>();// 实例基础信息
|
||||
for (DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance instance : body.getInstances().getInstance()){
|
||||
|
||||
InstanceInfo instanceInfo = new InstanceInfo();
|
||||
instanceInfo.setInstanceId(instance.getInstanceId());
|
||||
instanceInfo.setIpAddress(String.valueOf(instance.getPublicIpAddress().getIpAddress()));
|
||||
instanceInfo.setStatus(instance.getStatus());
|
||||
instanceInfos.add(instanceInfo);
|
||||
}
|
||||
log.info(Common.toJSONString(instanceInfos));
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
package com.muyu.web.common;
|
||||
|
||||
import net.sf.jsqlparser.statement.select.KSQLWindow;
|
||||
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class ScheduledThreadPool {
|
||||
/**
|
||||
* 周期线程数 CPU*2+1
|
||||
*/
|
||||
private static final ScheduledExecutorService scheduledThreadPool= Executors.newScheduledThreadPool(
|
||||
Runtime.getRuntime().availableProcessors()*2+1
|
||||
);
|
||||
|
||||
public static ScheduledFuture<?>submit(Runnable thread){
|
||||
// 参数分别是: 任务, 多久后开始执行, 每隔多久执行一次(周期),时间单位
|
||||
return submit(thread, 1);
|
||||
}
|
||||
|
||||
public static ScheduledFuture<?>submit(Runnable thread,long period){
|
||||
return scheduledThreadPool.scheduleAtFixedRate(thread,0,period, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭线程池
|
||||
*/
|
||||
public static void shutdown(){
|
||||
scheduledThreadPool.shutdown();
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
package com.muyu.web.controller;
|
||||
|
||||
import com.muyu.common.core.utils.uuid.UUID;
|
||||
import org.eclipse.paho.client.mqttv3.*;
|
||||
|
||||
public class testController {
|
||||
public static void main(String[] args) {
|
||||
String broker = "tcp://47.101.53.251:1883";
|
||||
String clientId = "SX-"+ UUID.randomUUID().toString();
|
||||
MqttClient client;
|
||||
|
||||
try {
|
||||
client = new MqttClient(broker, clientId);
|
||||
MqttConnectOptions connectOptions = new MqttConnectOptions();
|
||||
connectOptions.setCleanSession(true);
|
||||
System.out.println("Connect to broker:"+broker);
|
||||
client.connect(connectOptions);
|
||||
System.out.println("Connected");
|
||||
client.setCallback(new MqttCallback() {
|
||||
@Override
|
||||
public void connectionLost(Throwable throwable) {
|
||||
System.out.println("连接丢失");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void messageArrived(String topic, MqttMessage mqttMessage) throws Exception {
|
||||
System.out.println("消息到达:"+new String(mqttMessage.getPayload())+topic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
|
||||
|
||||
}
|
||||
});
|
||||
} catch (MqttException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
package com.muyu.web.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* mqtt配置类
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class MqttProperties {
|
||||
/**
|
||||
* 节点
|
||||
*/
|
||||
private String broker;
|
||||
|
||||
/**
|
||||
* 主题
|
||||
*/
|
||||
private String topic;
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 节点ID
|
||||
*/
|
||||
private String clientId;
|
||||
/**
|
||||
* 上报级别
|
||||
*/
|
||||
private int qos=0;
|
||||
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
package com.muyu.web.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.muyu.web.domain.model.ServerConfigModel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* 服务器配置类
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName(value = "server_config")
|
||||
public class ServerConfig {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(value = "id",type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
|
||||
/**
|
||||
* 主机地址
|
||||
*/
|
||||
private String host;
|
||||
|
||||
/**
|
||||
* 端口号
|
||||
*/
|
||||
private String port;
|
||||
|
||||
/**
|
||||
* 负载地址
|
||||
*/
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* 默认MOTT地址
|
||||
*/
|
||||
private String defaultMqttAddr;
|
||||
|
||||
/**
|
||||
* 默认MQTT主题
|
||||
*/
|
||||
private String defaultMqttTopic;
|
||||
|
||||
/**
|
||||
* 默认MOTT交付级别
|
||||
*/
|
||||
private Integer defaultMqttQos;
|
||||
|
||||
|
||||
public static ServerConfig modeBuild(ServerConfigModel serverConfigModel, Supplier<Long> idKey){
|
||||
return builder()
|
||||
.id(idKey.get())
|
||||
.host(serverConfigModel.getHost())
|
||||
.port(serverConfigModel.getPort())
|
||||
.url(serverConfigModel.getUrl())
|
||||
.defaultMqttAddr(serverConfigModel.getDefaultMqttAddr())
|
||||
.defaultMqttTopic(serverConfigModel.getDefaultMqttTopic())
|
||||
.defaultMqttQos(serverConfigModel.getDefaultMqttQos())
|
||||
.build();
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
package com.muyu.web.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@TableName("vehicle_info")
|
||||
public class VehicleInfo {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(
|
||||
value = "id",
|
||||
type = IdType.AUTO
|
||||
)
|
||||
private Long id;
|
||||
/**
|
||||
* VIN
|
||||
*/
|
||||
private String vin;
|
||||
/**
|
||||
* VIN
|
||||
*/
|
||||
@TableField(value = "tenant_id", fill = FieldFill.INSERT)
|
||||
private String tenantId;
|
||||
|
||||
/**
|
||||
* 报文模板
|
||||
*/
|
||||
@TableField("message_template_id")
|
||||
private Long messageTemplateId;
|
||||
|
||||
/**
|
||||
* 电池剩余电量
|
||||
*/
|
||||
@TableField("remaining_battery")
|
||||
private BigDecimal remainingBattery;
|
||||
|
||||
/**
|
||||
* 电池电量
|
||||
*/
|
||||
@TableField("battery_level")
|
||||
private BigDecimal batteryLevel;
|
||||
|
||||
/**
|
||||
* 上一次经度
|
||||
*/
|
||||
@TableField("last_longitude")
|
||||
private String lastLongitude;
|
||||
|
||||
/**
|
||||
* 上一次维度
|
||||
*/
|
||||
@TableField("last_latitude")
|
||||
private String lastLatitude;
|
||||
|
||||
/**
|
||||
* 总里程
|
||||
*/
|
||||
@TableField("total_mileage")
|
||||
private BigDecimal totalMileage;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||
private Date createTime;
|
||||
|
||||
|
||||
public static VehicleInfo create(String vin, Supplier<Long>messageTemplateId){
|
||||
return VehicleInfo.builder()
|
||||
.vin(vin)
|
||||
.messageTemplateId(messageTemplateId.get())
|
||||
.createTime(new Date())
|
||||
.totalMileage(BigDecimal.ZERO)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
package com.muyu.web.domain.model;
|
||||
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
Mqtt服务器模型
|
||||
*/
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class MqttServerModel {
|
||||
private static final Logger log=LoggerFactory.getLogger(MqttServerModel.class);
|
||||
|
||||
/**
|
||||
* MQTT服务节点
|
||||
*/
|
||||
private String broker;
|
||||
|
||||
/**
|
||||
* MQTT订阅主题
|
||||
*/
|
||||
private String topic;
|
||||
|
||||
public String getBroker(){
|
||||
log.info("broker:{}",broker);
|
||||
return broker.contains("tcp://")?broker:"tcp://"+broker+":1883";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
package com.muyu.web.domain.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @description: 位置模型
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class PositionModel {
|
||||
/**
|
||||
* 经度
|
||||
*/
|
||||
private String longitude;
|
||||
|
||||
/**
|
||||
* 维度
|
||||
*/
|
||||
private String latitude;
|
||||
|
||||
public static PositionModel strBuild (String positionStr) {
|
||||
String[] split = positionStr.split(",");
|
||||
return PositionModel.builder()
|
||||
.longitude(split[0])
|
||||
.latitude(split[1])
|
||||
.build();
|
||||
}
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
package com.muyu.web.domain.model;
|
||||
|
||||
import com.muyu.web.domain.ServerConfig;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ServerConfigModel {
|
||||
/**
|
||||
* 主机地址
|
||||
*/
|
||||
private String host;
|
||||
|
||||
/**
|
||||
* 端口号
|
||||
*/
|
||||
private String port;
|
||||
/**
|
||||
* 负载地址
|
||||
*/
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* 默认MOTT地址
|
||||
*/
|
||||
private String defaultMqttAddr;
|
||||
|
||||
/**
|
||||
* 默认MQTT主题
|
||||
*/
|
||||
private String defaultMqttTopic;
|
||||
|
||||
/**
|
||||
* 默认MOTT交付级别
|
||||
*/
|
||||
private Integer defaultMqttQos;
|
||||
|
||||
public static ServerConfigModel serverConfigModelBuild(ServerConfig serverConfig){
|
||||
return builder()
|
||||
.host(serverConfig.getHost().trim())
|
||||
.port(serverConfig.getPort())
|
||||
.url(serverConfig.getUrl().trim())
|
||||
.defaultMqttAddr(serverConfig.getDefaultMqttAddr().trim())
|
||||
.defaultMqttTopic(serverConfig.getDefaultMqttTopic().trim())
|
||||
.defaultMqttQos(serverConfig.getDefaultMqttQos())
|
||||
.build();
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
package com.muyu.web.domain.req;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class VehicleConnectionReq {
|
||||
|
||||
@JSONField(name = "vin")
|
||||
private String vin;
|
||||
|
||||
/**
|
||||
* 时间戳
|
||||
*/
|
||||
private String timestamp;
|
||||
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
@JSONField(name = "username")
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 随机字符串
|
||||
*/
|
||||
private String nonce;
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
package com.muyu.web.service;
|
||||
|
||||
public interface VehicleInstanceService {
|
||||
|
||||
|
||||
/**
|
||||
* 车辆客户端初始化
|
||||
*/
|
||||
void vehicleClientStart(String vin);
|
||||
|
||||
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
package com.muyu.web.service.impl;
|
||||
|
||||
import com.muyu.common.core.utils.uuid.UUID;
|
||||
import com.muyu.web.domain.req.VehicleConnectionReq;
|
||||
import com.muyu.web.service.VehicleInstanceService;
|
||||
import com.muyu.web.utils.MD5Util;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Log4j2
|
||||
@Service
|
||||
public class VehicleInstanceServiceImpl implements VehicleInstanceService {
|
||||
@Override
|
||||
public void vehicleClientStart(String vin) {
|
||||
log.info("车辆{},开始上线",vin);
|
||||
String timestamp = String.valueOf(System.currentTimeMillis());
|
||||
VehicleConnectionReq.builder()
|
||||
.vin(vin)
|
||||
.timestamp(timestamp)
|
||||
.userName(MD5Util.encrypted(vin+timestamp))
|
||||
.nonce(MD5Util.encrypted(UUID.randomUUID().toString().replace("-","")))
|
||||
.build();
|
||||
//
|
||||
}
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
package com.muyu.web.utils;
|
||||
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
|
||||
@Log4j2
|
||||
public class MD5Util {
|
||||
private static final Integer SALT_LENGTH = 12;
|
||||
|
||||
/**
|
||||
* 指定数组转化为16进制字符串
|
||||
*/
|
||||
public static String byteToHexString(byte[]b){
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (byte value : b) {
|
||||
String hex = Integer.toHexString(value & 0xFF);
|
||||
if (hex.length()==1){
|
||||
hex='0'+hex;
|
||||
}
|
||||
stringBuilder.append(hex.toUpperCase());
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得加密后的口令
|
||||
*/
|
||||
public static String encrypted(String str){
|
||||
try {
|
||||
byte[]pwd=null;
|
||||
SecureRandom random = new SecureRandom();
|
||||
byte[] salt = new byte[SALT_LENGTH];
|
||||
random.nextBytes(salt);
|
||||
MessageDigest md=null;
|
||||
md = MessageDigest.getInstance("MD5");
|
||||
md.update(salt);
|
||||
md.update(str.getBytes(StandardCharsets.UTF_8));
|
||||
byte[] digest = md.digest();
|
||||
pwd=new byte[digest.length+SALT_LENGTH];
|
||||
System.arraycopy(salt,0,pwd,0,SALT_LENGTH);
|
||||
System.arraycopy(digest,0,pwd,SALT_LENGTH,digest.length);
|
||||
return byteToHexString(pwd);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -7,7 +7,7 @@ nacos:
|
|||
addr: 47.101.53.251:8848
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: four
|
||||
namespace: yzl
|
||||
|
||||
# Spring
|
||||
spring:
|
||||
|
@ -54,3 +54,5 @@ logging:
|
|||
level:
|
||||
com.muyu.system.mapper: DEBUG
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
<artifactId>cloud-modules-wechat</artifactId>
|
||||
|
||||
<description>
|
||||
cloud-modules-wechat 微信公众号
|
||||
cloud-modules-wechat 微信公众号模块
|
||||
</description>
|
||||
|
||||
<properties>
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
<artifactId>cloud-modules</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
|
||||
<description>
|
||||
cloud-modules业务模块
|
||||
</description>
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
<modules>
|
||||
<module>saas-common</module>
|
||||
<module>saas-server</module>
|
||||
<module>saas-cache</module>
|
||||
</modules>
|
||||
|
||||
<description>
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
<?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>saas</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>saas-cache</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>
|
||||
saas-cache缓存模块
|
||||
</description>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu.common</groupId>
|
||||
<artifactId>saas-common</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu.cache</groupId>
|
||||
<artifactId>cloud-common-cache</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,32 @@
|
|||
package com.muyu.cache;
|
||||
|
||||
import com.muyu.common.domain.database.ElectronicFence;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @Author YuPing
|
||||
* @Description 电子围栏缓存
|
||||
* @Version 1.0
|
||||
* @Data 2024-09-29 20:53:46
|
||||
*/
|
||||
@Component
|
||||
public class ElectronicFenceCacheService extends CacheAbsBasic<String, ElectronicFence>{
|
||||
/**
|
||||
* key前缀
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String keyPre() {
|
||||
return "electronicFence";
|
||||
}
|
||||
|
||||
/**
|
||||
* 解码
|
||||
* @param key 编码key
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String decode(String key) {
|
||||
return key.replace(keyPre(), "");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.muyu.cache;
|
||||
|
||||
import com.muyu.common.domain.database.ElectronicFenceGroup;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @Author YuPing
|
||||
* @Description 围栏组缓存
|
||||
* @Version 1.0
|
||||
* @Data 2024-09-29 20:57:46
|
||||
*/
|
||||
@Component
|
||||
public class ElectronicFenceGroupCacheService extends CacheAbsBasic<String, ElectronicFenceGroup>{
|
||||
/**
|
||||
* key前缀
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String keyPre() {
|
||||
return "electronicFenceGroup";
|
||||
}
|
||||
|
||||
/**
|
||||
* 解码
|
||||
* @param key 编码key
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String decode(String key) {
|
||||
return key.replace(keyPre(), "");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.muyu.cache;
|
||||
|
||||
import com.muyu.common.domain.Enterprise;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author yuping
|
||||
* @package com.muyu.cache
|
||||
* @name EnterpriseCacheService
|
||||
* @date 2024/9/29 20:21 企业缓存
|
||||
*/
|
||||
@Component
|
||||
public class EnterpriseCacheService extends CacheAbsBasic<String, Enterprise>{
|
||||
/**
|
||||
* 缓存前缀
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String keyPre() {
|
||||
return "enterprise:info:";
|
||||
}
|
||||
|
||||
/**
|
||||
* 解码
|
||||
* @param key 编码key
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String decode(String key) {
|
||||
return key.replace(keyPre(), "");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.muyu.cache;
|
||||
|
||||
import com.muyu.common.domain.SysCarFault;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @Author YuPing
|
||||
* @Description 故障缓存
|
||||
* @Version 1.0
|
||||
* @Data 2024-09-29 21:10:31
|
||||
*/
|
||||
@Component
|
||||
public class SysCarFaultCacheService extends CacheAbsBasic<String, SysCarFault>{
|
||||
/**
|
||||
* 缓存前缀
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String keyPre() {
|
||||
return "sysCarFault";
|
||||
}
|
||||
|
||||
/**
|
||||
* 解码
|
||||
* @param key 编码key
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String decode(String key) {
|
||||
return key.replace(keyPre(), "");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package com.muyu.cache;
|
||||
|
||||
import com.muyu.common.domain.SysCarFaultMessage;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @Author YuPing
|
||||
* @Description 站内信缓存
|
||||
* @Version 1.0
|
||||
* @Data 2024-09-29 21:13:19
|
||||
*/
|
||||
@Component
|
||||
public class SysCarFaultMessageCacheService extends CacheAbsBasic<String, SysCarFaultMessage>{
|
||||
@Override
|
||||
public String keyPre() {
|
||||
return "sysCarFaultMessage";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String decode(String key) {
|
||||
return key.replace(keyPre(), "");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
com.muyu.cache.ElectronicFenceCacheService
|
||||
com.muyu.cache.ElectronicFenceGroupCacheService
|
||||
com.muyu.cache.EnterpriseCacheService
|
||||
com.muyu.cache.SysCarFaultCacheService
|
||||
com.muyu.cache.SysCarFaultMessageCacheService
|
|
@ -7,12 +7,11 @@ import lombok.Data;
|
|||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 车辆类型对象
|
||||
* @Author:liuxinyue
|
||||
* @Package:com.sheep.message.domain
|
||||
* @Project:cloud-server-c
|
||||
* @name:MessageTemplateType
|
||||
* @Date:2024/9/18 21:01
|
||||
* 车辆类型
|
||||
* @author sx
|
||||
* @package com.muyu.common.domain
|
||||
* @name CarType
|
||||
* @date 2024/9/22 14:36
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
|
|
|
@ -10,8 +10,8 @@ import lombok.NoArgsConstructor;
|
|||
import lombok.experimental.SuperBuilder;
|
||||
import java.io.Serializable;
|
||||
/**
|
||||
* 数据类型对象
|
||||
* @Author:liuxinyue
|
||||
* 数据类型表
|
||||
* @author liuxinyue
|
||||
* @Package:com.sheep.message.domain
|
||||
* @Project:cloud-server-c
|
||||
* @name:DataType
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
package com.muyu.common.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author YuPing
|
||||
* 企业运营实体类
|
||||
* @author yuping
|
||||
* @Description 企业运营实体类
|
||||
* @Version 1.0
|
||||
* @Data 2024-09-26 20:22:04
|
||||
|
@ -13,6 +15,7 @@ import lombok.NoArgsConstructor;
|
|||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("enterprise")
|
||||
public class Enterprise {
|
||||
/**
|
||||
* 企业编号
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.muyu.common.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
@ -9,8 +10,8 @@ import lombok.experimental.SuperBuilder;
|
|||
import java.sql.Date;
|
||||
|
||||
/**
|
||||
* 新能源车模版
|
||||
* @Author:liuxinyue
|
||||
* 报文模版
|
||||
* @author liuxinyue
|
||||
* @Package:com.template.domain
|
||||
* @Project:cloud-server
|
||||
* @name:MessageTemplate
|
||||
|
@ -21,6 +22,7 @@ import java.sql.Date;
|
|||
@NoArgsConstructor
|
||||
@SuperBuilder
|
||||
@Tag(name = "报文")
|
||||
@TableName("message_template")
|
||||
public class MessageTemplate {
|
||||
|
||||
/**
|
||||
|
|
|
@ -11,7 +11,6 @@ import lombok.experimental.SuperBuilder;
|
|||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 模版对应的配置
|
||||
* @Author:liuxinyue
|
||||
* @Package:com.sheep.message.domain
|
||||
* @Project:cloud-server-c
|
||||
|
@ -26,7 +25,6 @@ import java.io.Serializable;
|
|||
@TableName(value = "message_template_type",autoResultMap = true)
|
||||
public class MessageTemplateType implements Serializable {
|
||||
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
|
|
|
@ -10,12 +10,11 @@ import lombok.EqualsAndHashCode;
|
|||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 车辆对象
|
||||
* @Author:liuxinyue
|
||||
* @Package:com.sheep.message.domain
|
||||
* @Project:cloud-server-c
|
||||
* @name:MessageTemplateType
|
||||
* @Date:2024/9/18 21:01
|
||||
* 车辆管理表
|
||||
* @author sx
|
||||
* @package com.muyu.common.domain
|
||||
* @name SysCar
|
||||
* @date 2024-09-29 14:39:33
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
|
@ -23,7 +22,6 @@ import lombok.NoArgsConstructor;
|
|||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName(value = "sys_car",autoResultMap = true)
|
||||
public class SysCar extends BaseEntity {
|
||||
|
||||
@TableId(value = "id",type = IdType.AUTO)
|
||||
private Long id;
|
||||
private String carVin;
|
||||
|
|
|
@ -9,7 +9,7 @@ import lombok.*;
|
|||
|
||||
/**
|
||||
* 企业信息 sys_car_enterprise
|
||||
* @author YuanZiLong
|
||||
* @author 袁子龙
|
||||
* @package com.muyu.breakdown.domain
|
||||
* @name: SysCarEnterprise
|
||||
* @date: 2024/9/26 19:54
|
||||
|
|
|
@ -12,7 +12,7 @@ import org.apache.commons.lang3.builder.ToStringStyle;
|
|||
|
||||
/**
|
||||
* 车辆故障管理对象 sys_car_fault
|
||||
* @author YuanZiLong
|
||||
* @author 袁子龙
|
||||
* @package: com.muyu.breakdown.domain
|
||||
* @name: SysCarFault
|
||||
* @date: 2024/9/20 10:56
|
||||
|
|
|
@ -12,7 +12,7 @@ import java.util.Date;
|
|||
|
||||
/**
|
||||
* 故障记录对象 sys_car_fault_log
|
||||
* @author YuanZiLong
|
||||
* @author 袁子龙
|
||||
* @package: com.muyu.breakdown.domain
|
||||
* @name: SysCarFaultLog
|
||||
* @date: 2024/9/22 20:17
|
||||
|
|
|
@ -11,7 +11,7 @@ import java.util.Date;
|
|||
|
||||
/**
|
||||
* 站内信息对象 sys_car_fault_message
|
||||
* @author YuanZiLong
|
||||
* @author 袁子龙
|
||||
* @package: com.muyu.breakdown.domain
|
||||
* @name: SysCarFaultMessage
|
||||
* @date: 2024/9/22 11:57
|
||||
|
|
|
@ -11,12 +11,11 @@ import lombok.NoArgsConstructor;
|
|||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 车辆记录对象
|
||||
* @Author:liuxinyue
|
||||
* @Package:com.sheep.message.domain
|
||||
* @Project:cloud-server-c
|
||||
* @name:MessageTemplateType
|
||||
* @Date:2024/9/18 21:01
|
||||
* 车辆上下线记录表
|
||||
* @author sx
|
||||
* @package com.muyu.common.domain
|
||||
* @name SysCarLog
|
||||
* @date 2024-09-29 14:34:15
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
|
|
|
@ -14,13 +14,14 @@ import org.springframework.format.annotation.DateTimeFormat;
|
|||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 报文模版对象
|
||||
* @Author:liuxinyue
|
||||
* 报文模版
|
||||
* @author liuxinyue
|
||||
* @Package:com.template.domain
|
||||
* @Project:cloud-server-c
|
||||
* @name:Template
|
||||
* @Date:2024/9/20 12:04
|
||||
*/
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
|
|
|
@ -14,7 +14,7 @@ import java.util.Date;
|
|||
/**
|
||||
* 预警日志对象 warn_logs
|
||||
*
|
||||
* @author muyu
|
||||
* @author sx
|
||||
* @date 2024-09-20
|
||||
*/
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ import lombok.NoArgsConstructor;
|
|||
/**
|
||||
* 预警规则对象 warn_rule
|
||||
*
|
||||
* @author muyu
|
||||
* @author sx
|
||||
* @date 2024-09-20
|
||||
*/
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ import lombok.NoArgsConstructor;
|
|||
/**
|
||||
* 预警策略对象 warn_strategy
|
||||
*
|
||||
* @author muyu
|
||||
* @author sx
|
||||
* @date 2024-09-20
|
||||
*/
|
||||
|
||||
|
|
|
@ -16,7 +16,8 @@ import lombok.experimental.SuperBuilder;
|
|||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* @Author:yuping
|
||||
* 电子围栏表
|
||||
* @author yuping
|
||||
* @Package:com.muyu.fence.domain
|
||||
* @Project:cloud-server
|
||||
* @name:ElectronicFence
|
||||
|
|
|
@ -16,7 +16,8 @@ import lombok.experimental.SuperBuilder;
|
|||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* @Author:yuping
|
||||
* 围栏组
|
||||
* @author yuping
|
||||
* @Package:com.muyu.fence.domain
|
||||
* @Project:cloud-server
|
||||
* @name:ElectronicFenceGroup
|
||||
|
|
|
@ -9,7 +9,8 @@ import lombok.Data;
|
|||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author:yuping
|
||||
* 围栏组连接表
|
||||
* @author yuping
|
||||
* @Package:com.muyu.fence.domain
|
||||
* @Project:cloud-server
|
||||
* @name:FenceGroupMid
|
||||
|
|
|
@ -10,7 +10,8 @@ import lombok.NoArgsConstructor;
|
|||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Author:yuping
|
||||
* 电动围栏添加请求参数
|
||||
* @author yuping
|
||||
* @Package:com.muyu.fence.domain.req
|
||||
* @Project:cloud-server
|
||||
* @name:ElectroicAdd
|
||||
|
|
|
@ -8,7 +8,8 @@ import lombok.NoArgsConstructor;
|
|||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Author:yuping
|
||||
* 电子围栏列表请求参数
|
||||
* @author yuping
|
||||
* @Package:com.muyu.fence.domain.req
|
||||
* @Project:cloud-server
|
||||
* @name:ElectroicFenceReq
|
||||
|
|
|
@ -6,7 +6,8 @@ import lombok.Data;
|
|||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author:yuping
|
||||
* 电子围栏更新请求参数
|
||||
* @author yuping
|
||||
* @Package:com.muyu.fence.domain.req
|
||||
* @Project:cloud-server
|
||||
* @name:ElectroicFenceUpdReq
|
||||
|
|
|
@ -9,7 +9,8 @@ import lombok.NoArgsConstructor;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:yuping
|
||||
* 围栏组添加请求参数
|
||||
* @author yuping
|
||||
* @Package:com.muyu.fence.domain.req
|
||||
* @Project:cloud-server
|
||||
* @name:ElectronicFenceGroupAddReq
|
||||
|
|
|
@ -8,7 +8,8 @@ import lombok.Data;
|
|||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author:yuping
|
||||
* 围栏组列表请求参数
|
||||
* @author yuping
|
||||
* @Package:com.muyu.fence.domain.req
|
||||
* @Project:cloud-server
|
||||
* @name:ElectronicFenceGroupListReq
|
||||
|
|
|
@ -11,7 +11,8 @@ import lombok.NoArgsConstructor;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:yuping
|
||||
* 围栏组修改请求参数
|
||||
* @author yuping
|
||||
* @Package:com.muyu.fence.domain.req
|
||||
* @Project:cloud-server
|
||||
* @name:ElectronicFenceGroupAddReq
|
||||
|
|
|
@ -9,7 +9,8 @@ import lombok.NoArgsConstructor;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:yuping
|
||||
* 用于绑定围栏和围栏组的请求
|
||||
* @author yuping
|
||||
* @Package:com.muyu.fence.domain.req
|
||||
* @Project:cloud-server
|
||||
* @name:FenceAndGroupBoundReq
|
||||
|
|
|
@ -5,7 +5,8 @@ import lombok.Data;
|
|||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author:yuping
|
||||
*围栏方式请求参数
|
||||
* @author yuping
|
||||
* @Package:com.muyu.fence.domain
|
||||
* @Project:cloud-server
|
||||
* @name:FenceWay
|
||||
|
|
|
@ -5,6 +5,13 @@ import lombok.AllArgsConstructor;
|
|||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 汽车请求参数
|
||||
* @author sx
|
||||
* @package com.muyu.common.domain.req
|
||||
* @name SysCarReq
|
||||
* @date 2024/9/22 14:36
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
|
|
|
@ -8,7 +8,7 @@ import lombok.NoArgsConstructor;
|
|||
/**
|
||||
* 预警策略对象 warn_strategy
|
||||
*
|
||||
* @author muyu
|
||||
* @author sx
|
||||
* @date 2024-09-20
|
||||
*/
|
||||
|
||||
|
|
|
@ -8,6 +8,13 @@ import lombok.Data;
|
|||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 车辆类型返回对象
|
||||
* @author sx
|
||||
* @package com.muyu.common.domain.resp
|
||||
* @name CarTypeResp
|
||||
* @date 2024/9/22 14:36
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
|
|
|
@ -10,12 +10,13 @@ import lombok.NoArgsConstructor;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @Author:yuping
|
||||
* @Package:com.muyu.fence.domain.resp
|
||||
* @Project:cloud-server
|
||||
* @name:ElectronicFenceGroupResp
|
||||
* @Date:2024/9/22 10:22
|
||||
* 回显围栏组及绑定的电子围栏
|
||||
* @author yuping
|
||||
* @package com.muyu.fence.domain.resp
|
||||
* @name ElectronicFenceGroupResp
|
||||
* @date 2024/9/22 14:36
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
|
|
|
@ -7,12 +7,14 @@ import lombok.NoArgsConstructor;
|
|||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* @Author:yuping
|
||||
*电子围栏组
|
||||
* @author yuping
|
||||
* @Package:com.muyu.fence.domain
|
||||
* @Project:cloud-server
|
||||
* @name:ElectronicFence
|
||||
* @Date:2024/9/17 16:34
|
||||
*/
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
|
|
|
@ -9,7 +9,8 @@ import lombok.Data;
|
|||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author:yuping
|
||||
* 围栏组列表
|
||||
* @author yuping
|
||||
* @Package:com.muyu.fence.domain.req
|
||||
* @Project:cloud-server
|
||||
* @name:GroupFenceListresp
|
||||
|
|
|
@ -6,7 +6,8 @@ import lombok.Data;
|
|||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author:liuxinyue
|
||||
* 故障记录
|
||||
* @author liuxinyue
|
||||
* @Package:com.muyu.domain.resp
|
||||
* @Project:cloud-server
|
||||
* @name:SysCarFaultLogVo
|
||||
|
|
|
@ -7,6 +7,13 @@ import lombok.Data;
|
|||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 车辆管理返回值
|
||||
* @author sx
|
||||
* @package com.muyu.common.domain.resp
|
||||
* @name SysCarVo
|
||||
* @date 2024/9/22 14:36
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
|
|
|
@ -7,6 +7,13 @@ import lombok.AllArgsConstructor;
|
|||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 预警日志对象
|
||||
* @author sx
|
||||
* @package com.muyu.common.domain.resp
|
||||
* @name WarnLogsResp
|
||||
* @date 2024/9/22 14:36
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
|
|
|
@ -6,6 +6,13 @@ import lombok.AllArgsConstructor;
|
|||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 预警规则返回对象
|
||||
* @author sx
|
||||
* @package com.muyu.common.domain.resp
|
||||
* @name WarnRuleResp
|
||||
* @date 2024/9/22 14:36
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
|
|
|
@ -7,6 +7,13 @@ import lombok.AllArgsConstructor;
|
|||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 预警策略返回对象
|
||||
* @author sx
|
||||
* @package com.muyu.common.domain.resp
|
||||
* @anme WarnStrategyResp
|
||||
* @date 2024/9/22 14:36
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
|
|
|
@ -14,6 +14,10 @@ import lombok.NoArgsConstructor;
|
|||
|
||||
/**
|
||||
* 电子围栏规则计算模型
|
||||
* @author yuping
|
||||
* @package com.muyu.fence.domain
|
||||
* @name ElectricFenceModel
|
||||
* @date 2024/9/22 14:36
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
|
|
|
@ -15,6 +15,10 @@ import java.util.Date;
|
|||
*/
|
||||
/**
|
||||
* 电子围栏转换临时对象
|
||||
* @author yuping
|
||||
* @package com.muyu.fence.domain.utils
|
||||
* @name ElectricFenceResultTmp
|
||||
* @date 2024/9/22 14:36
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
|
|
|
@ -18,6 +18,10 @@ import java.util.Date;
|
|||
|
||||
/**
|
||||
* 电子围栏分析结果数据结构
|
||||
* @author yuping
|
||||
* @package com.muyu.fence.domain
|
||||
* @name ElectronicFenceResult
|
||||
* @date 2024/9/22 14:36
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
|
|
|
@ -10,7 +10,8 @@ import lombok.NoArgsConstructor;
|
|||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* @Author:yuping
|
||||
*电子围栏设置
|
||||
* @author yuping
|
||||
* @Package:com.muyu.fence.domain
|
||||
* @Project:cloud-server
|
||||
* @name:ElectronicFenceSetting
|
||||
|
|
|
@ -1,239 +0,0 @@
|
|||
package com.muyu.common.util;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* kafka通用配置
|
||||
* @author liuxinyue
|
||||
* @Package:com.muyu.common.util
|
||||
* @name:KafkaCommonProperties
|
||||
* @Date:2024/9/29 12:26
|
||||
*/
|
||||
public class KafkaCommonProperties{
|
||||
|
||||
/**
|
||||
* Kafka主机
|
||||
*/
|
||||
private String kafkaHost = "47.101.53.251:9092";
|
||||
|
||||
/**
|
||||
* 生产者:要求leader请求结束前收到的确认次数,来控制发送数据的持久化
|
||||
* 消息确认:
|
||||
* 0:生产者不等待服务器确认,此时retry参数不生效
|
||||
* 1:leader写入记录到log,不会等待follower的确认即向生产者发送通知
|
||||
* all:leader等待所有副本通知,然后向生产者发送通知,保证所有数据落盘到所有副本,功能同设置为-1
|
||||
*/
|
||||
private String ack = "all";
|
||||
|
||||
/**
|
||||
* 生产者重试次数
|
||||
*/
|
||||
private Integer retryTimes = 1;
|
||||
|
||||
/**
|
||||
* 生产者:向同一分区发送打包发送的数据量,单位:bytes,默认16384bytes=16K
|
||||
*/
|
||||
private Integer batchSize = 16384;
|
||||
|
||||
/**
|
||||
* 生产者:批量发送消息的间隔时间(延迟时间),单位:毫秒
|
||||
*/
|
||||
private Integer lingerMs = 1;
|
||||
|
||||
/**
|
||||
* 生产者:可以使用的最大缓存空间,单位:bytes,默认33554432bytes=32M.
|
||||
*/
|
||||
private Integer bufferMemory = 33554432;
|
||||
|
||||
/**
|
||||
* 生产者:键编码器
|
||||
*/
|
||||
private String keyEncoder = "org.apache.kafka.common.serialization.StringSerializer";
|
||||
|
||||
/**
|
||||
* 生产者:值编码器
|
||||
*/
|
||||
private String valueEncoder = "org.apache.kafka.common.serialization.StringSerializer";
|
||||
|
||||
/**
|
||||
* 消费者:消费topic的组ID
|
||||
*/
|
||||
private String groupId = "my-group-id";
|
||||
|
||||
/**
|
||||
* 消费者:后台定期提交offset
|
||||
*/
|
||||
private String autoCommit = "true";
|
||||
|
||||
/**
|
||||
* 消费者提交offset的时间间隔:单位:毫秒,当enable.auto.commit为true时生效
|
||||
*/
|
||||
private String autoCommitIntervalMs = "1000";
|
||||
|
||||
/**
|
||||
* 消费者:键解码器
|
||||
*/
|
||||
private String keyDecoder = "org.apache.kafka.common.serialization.StringDeserializer";
|
||||
|
||||
/**
|
||||
* 消费者:值解码器
|
||||
*/
|
||||
private String valueDecoder = "org.apache.kafka.common.serialization.StringDeserializer";
|
||||
|
||||
/**
|
||||
* 消费者:重启后配置offset
|
||||
* earliest:消费者恢复到当前topic最早的offset
|
||||
* latest:消费者从最新的offset开始消费
|
||||
* none:如果消费者组没找到之前的offset抛出异常
|
||||
* 其他任何值都会抛出异常
|
||||
*/
|
||||
private String autoOffsetReset = "latest";
|
||||
|
||||
/**
|
||||
* TOPIC
|
||||
*/
|
||||
private Collection<String> topic = Collections.singleton("my-topic");
|
||||
|
||||
public KafkaCommonProperties() {
|
||||
|
||||
}
|
||||
|
||||
public KafkaCommonProperties(String kafkaHost, String ack, Integer retryTimes, Integer batchSize, Integer lingerMs, Integer bufferMemory, String keyEncoder, String valueEncoder, String groupId, String autoCommit, String autoCommitIntervalMs, String keyDecoder, String valueDecoder, String autoOffsetReset, Collection<String> topic) {
|
||||
this.kafkaHost = kafkaHost;
|
||||
this.ack = ack;
|
||||
this.retryTimes = retryTimes;
|
||||
this.batchSize = batchSize;
|
||||
this.lingerMs = lingerMs;
|
||||
this.bufferMemory = bufferMemory;
|
||||
this.keyEncoder = keyEncoder;
|
||||
this.valueEncoder = valueEncoder;
|
||||
this.groupId = groupId;
|
||||
this.autoCommit = autoCommit;
|
||||
this.autoCommitIntervalMs = autoCommitIntervalMs;
|
||||
this.keyDecoder = keyDecoder;
|
||||
this.valueDecoder = valueDecoder;
|
||||
this.autoOffsetReset = autoOffsetReset;
|
||||
this.topic = topic;
|
||||
}
|
||||
|
||||
public String getKafkaHost() {
|
||||
return kafkaHost;
|
||||
}
|
||||
|
||||
public void setKafkaHost(String kafkaHost) {
|
||||
this.kafkaHost = kafkaHost;
|
||||
}
|
||||
|
||||
public String getAck() {
|
||||
return ack;
|
||||
}
|
||||
|
||||
public void setAck(String ack) {
|
||||
this.ack = ack;
|
||||
}
|
||||
|
||||
public Integer getRetryTimes() {
|
||||
return retryTimes;
|
||||
}
|
||||
|
||||
public void setRetryTimes(Integer retryTimes) {
|
||||
this.retryTimes = retryTimes;
|
||||
}
|
||||
|
||||
public Integer getBatchSize() {
|
||||
return batchSize;
|
||||
}
|
||||
|
||||
public void setBatchSize(Integer batchSize) {
|
||||
this.batchSize = batchSize;
|
||||
}
|
||||
|
||||
public Integer getLingerMs() {
|
||||
return lingerMs;
|
||||
}
|
||||
|
||||
public void setLingerMs(Integer lingerMs) {
|
||||
this.lingerMs = lingerMs;
|
||||
}
|
||||
|
||||
public Integer getBufferMemory() {
|
||||
return bufferMemory;
|
||||
}
|
||||
|
||||
public void setBufferMemory(Integer bufferMemory) {
|
||||
this.bufferMemory = bufferMemory;
|
||||
}
|
||||
|
||||
public String getKeyEncoder() {
|
||||
return keyEncoder;
|
||||
}
|
||||
|
||||
public void setKeyEncoder(String keyEncoder) {
|
||||
this.keyEncoder = keyEncoder;
|
||||
}
|
||||
|
||||
public String getValueEncoder() {
|
||||
return valueEncoder;
|
||||
}
|
||||
|
||||
public void setValueEncoder(String valueEncoder) {
|
||||
this.valueEncoder = valueEncoder;
|
||||
}
|
||||
|
||||
public String getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public void setGroupId(String groupId) {
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
public String getAutoCommit() {
|
||||
return autoCommit;
|
||||
}
|
||||
|
||||
public void setAutoCommit(String autoCommit) {
|
||||
this.autoCommit = autoCommit;
|
||||
}
|
||||
|
||||
public String getAutoCommitIntervalMs() {
|
||||
return autoCommitIntervalMs;
|
||||
}
|
||||
|
||||
public void setAutoCommitIntervalMs(String autoCommitIntervalMs) {
|
||||
this.autoCommitIntervalMs = autoCommitIntervalMs;
|
||||
}
|
||||
|
||||
public String getKeyDecoder() {
|
||||
return keyDecoder;
|
||||
}
|
||||
|
||||
public void setKeyDecoder(String keyDecoder) {
|
||||
this.keyDecoder = keyDecoder;
|
||||
}
|
||||
|
||||
public String getValueDecoder() {
|
||||
return valueDecoder;
|
||||
}
|
||||
|
||||
public void setValueDecoder(String valueDecoder) {
|
||||
this.valueDecoder = valueDecoder;
|
||||
}
|
||||
|
||||
public String getAutoOffsetReset() {
|
||||
return autoOffsetReset;
|
||||
}
|
||||
|
||||
public void setAutoOffsetReset(String autoOffsetReset) {
|
||||
this.autoOffsetReset = autoOffsetReset;
|
||||
}
|
||||
|
||||
public Collection<String> getTopic() {
|
||||
return topic;
|
||||
}
|
||||
|
||||
public void setTopic(Collection<String> topic) {
|
||||
this.topic = topic;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.muyu.common.util;
|
||||
|
||||
/**
|
||||
* @author liuxinyue
|
||||
* @Package:com.muyu.common.util
|
||||
* @name:KafkaConstants
|
||||
* @Date:2024/9/29 20:22
|
||||
*/
|
||||
public class KafkaConstants {
|
||||
|
||||
|
||||
public final static String KafkaTopic="kafka_topic_test";
|
||||
|
||||
public final static String KafkaGrop="kafka_group_test";
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package com.muyu.common.util;
|
||||
|
||||
import org.apache.kafka.clients.consumer.KafkaConsumer;
|
||||
import org.apache.kafka.common.serialization.Deserializer;
|
||||
import org.apache.kafka.common.serialization.StringDeserializer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* @author liuxinyue
|
||||
* @Package:com.muyu.common.util
|
||||
* @name:KafkaConsumerConfig
|
||||
* @Date:2024/9/29 20:19
|
||||
*/
|
||||
@Configuration
|
||||
public class KafkaConsumerConfig
|
||||
{
|
||||
|
||||
@Bean
|
||||
public KafkaConsumer kafkaConsumer(){
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("bootstrap.servers", "47.101.53.251:9092");
|
||||
map.put("enable.auto.commit",true);
|
||||
map.put("auto.commit.interval", 5000);
|
||||
map.put("auto.offset.reset", "latest");
|
||||
map.put("fetch.max.wait", 500);
|
||||
map.put("fetch.min.size", 1);
|
||||
map.put("heartbeat-interval", 3000);
|
||||
map.put("max.poll.records", 500);
|
||||
map.put("group.id", KafkaConstants.KafkaGrop);
|
||||
//指定key使用的反序列化类
|
||||
Deserializer keyDeserializer = new StringDeserializer();
|
||||
//指定value使用的反序列化类
|
||||
Deserializer valueDeserializer = new StringDeserializer();
|
||||
//创建Kafka消费者
|
||||
KafkaConsumer kafkaConsumer = new KafkaConsumer(map, keyDeserializer, valueDeserializer);
|
||||
return kafkaConsumer;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
package com.muyu.common.util;
|
||||
|
||||
import org.apache.kafka.clients.producer.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Properties;
|
||||
/**
|
||||
* kafka生产
|
||||
* @author liuxinyue
|
||||
* @Package:com.muyu.common.util
|
||||
* @name:KafkaProducerTest
|
||||
* @Date:2024/9/29 12:27
|
||||
*/
|
||||
public class KafkaProducerTest {
|
||||
private static final Logger logger = LoggerFactory.getLogger(KafkaProducerTest.class);
|
||||
|
||||
public static KafkaProducer<String, String> getDefaultKafkaProducer(KafkaCommonProperties kafkaCommonProperties) {
|
||||
Properties properties = new Properties();
|
||||
properties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, kafkaCommonProperties.getKafkaHost());
|
||||
properties.put(ProducerConfig.ACKS_CONFIG, kafkaCommonProperties.getAck());
|
||||
properties.put(ProducerConfig.RETRIES_CONFIG, kafkaCommonProperties.getRetryTimes());
|
||||
properties.put(ProducerConfig.BATCH_SIZE_CONFIG, kafkaCommonProperties.getBatchSize());
|
||||
properties.put(ProducerConfig.LINGER_MS_CONFIG, kafkaCommonProperties.getLingerMs());
|
||||
properties.put(ProducerConfig.BUFFER_MEMORY_CONFIG, kafkaCommonProperties.getBufferMemory());
|
||||
properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, kafkaCommonProperties.getKeyEncoder());
|
||||
properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, kafkaCommonProperties.getValueEncoder());
|
||||
return new KafkaProducer<>(properties);
|
||||
}
|
||||
|
||||
static class MyProducerCallback implements Callback {
|
||||
|
||||
@Override
|
||||
public void onCompletion(RecordMetadata metadata, Exception exception) {
|
||||
if (Objects.nonNull(exception)) {
|
||||
logger.error(">>>>>>>>>>Producer生产消息异常:", exception);
|
||||
}
|
||||
if (Objects.nonNull(metadata)) {
|
||||
logger.info(">>>>>>>>>>Producer生产消息:metadata:{},partition:{}, offset:{}", metadata, metadata.partition(), metadata.offset());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
KafkaCommonProperties kafkaCommonProperties = new KafkaCommonProperties();
|
||||
KafkaProducer<String, String> producer = getDefaultKafkaProducer(kafkaCommonProperties);
|
||||
String message = "hello world ";
|
||||
try {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
// 异步写入数据
|
||||
String topic = kafkaCommonProperties.getTopic().toArray()[0].toString();
|
||||
ProducerRecord<String, String> producerRecord = new ProducerRecord<>(topic, message + i);
|
||||
producer.send(producerRecord, new MyProducerCallback());
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error(">>>>>>>>生产数据异常:", ex);
|
||||
throw new RuntimeException(ex);
|
||||
} finally {
|
||||
producer.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue