对接阿里云的RunInstances接口创建实例

dev.car.gateway
冷调 2024-09-29 09:06:47 +08:00
parent f5b153f32c
commit 723cb6556d
36 changed files with 1246 additions and 18 deletions

View File

@ -4,7 +4,7 @@ server:
# nacos线上地址 # nacos线上地址
nacos: nacos:
addr: 127.0.0.1:8848 addr: 106.54.193.225:8848
user-name: nacos user-name: nacos
password: nacos password: nacos
namespace: one-saas namespace: one-saas

View File

@ -168,6 +168,11 @@
<groupId>cn.hutool</groupId> <groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId> <artifactId>hutool-all</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<version>1.2.2</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -58,7 +58,7 @@ public class IpUtils {
ip = request.getRemoteAddr(); ip = request.getRemoteAddr();
} }
return "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : getMultistageReverseProxyIp(ip); return "0:0:0:0:0:0:0:1".equals(ip) ? "106.54.193.225" : getMultistageReverseProxyIp(ip);
} }
/** /**
@ -70,7 +70,7 @@ public class IpUtils {
*/ */
public static boolean internalIp (String ip) { public static boolean internalIp (String ip) {
byte[] addr = textToNumericFormatV4(ip); byte[] addr = textToNumericFormatV4(ip);
return internalIp(addr) || "127.0.0.1".equals(ip); return internalIp(addr) || "106.54.193.225".equals(ip);
} }
/** /**
@ -197,7 +197,7 @@ public class IpUtils {
return InetAddress.getLocalHost().getHostAddress(); return InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) { } catch (UnknownHostException e) {
} }
return "127.0.0.1"; return "106.54.193.225";
} }
/** /**

View File

@ -13,7 +13,7 @@ public class DatasourceContent {
public final static String PASSWORD = "bawei2112A"; public final static String PASSWORD = "bawei2112A";
public final static String IP = "127.0.0.1"; public final static String IP = "106.54.193.225";
public final static Integer PORT = 3306; public final static Integer PORT = 3306;
} }

View File

@ -4,7 +4,7 @@ server:
# nacos线上地址 # nacos线上地址
nacos: nacos:
addr: 127.0.0.1:8848 addr: 106.54.193.225:8848
user-name: nacos user-name: nacos
password: nacos password: nacos
namespace: one-saas namespace: one-saas
@ -50,7 +50,7 @@ spring:
eager: true eager: true
transport: transport:
# 控制台地址 # 控制台地址
dashboard: 127.0.0.1:8718 dashboard: 106.54.193.225:8718
# nacos配置持久化 # nacos配置持久化
datasource: datasource:
ds1: ds1:

View File

@ -1,10 +1,10 @@
# Tomcat # Tomcat
server: server:
port: 9702 port: 10022
# nacos线上地址 # nacos线上地址
nacos: nacos:
addr: 127.0.0.1:8848 addr: 106.54.193.225:8848
user-name: nacos user-name: nacos
password: nacos password: nacos
namespace: one namespace: one

View File

@ -0,0 +1,114 @@
<?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</artifactId>
<version>3.6.3</version>
</parent>
<artifactId>cloud-modules-car-gateway</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-core</artifactId>
</dependency>
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-security</artifactId>
</dependency>
<!-- 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>
<!-- &lt;!&ndash; XllJob定时任务 &ndash;&gt;-->
<!-- <dependency>-->
<!-- <groupId>com.muyu</groupId>-->
<!-- <artifactId>cloud-common-xxl</artifactId>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>com.muyu</groupId>-->
<!-- <artifactId>cloud-common-rabbit</artifactId>-->
<!-- </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>
</dependencies>
</project>

View File

@ -0,0 +1,23 @@
package com.muyu.cargateway;
import com.muyu.common.security.annotation.EnableCustomConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
/**
* @ ToolIntelliJ IDEA
* @ AuthorCHX
* @ Date2024-09-17-15:00
* @ Version1.0
* @ Description
* @author Lenovo
*/
@EnableCustomConfig
@EnableFeignClients
@SpringBootApplication
public class CarGatewayApplication {
public static void main(String[] args) {
SpringApplication.run(CarGatewayApplication.class, args);
}
}

View File

@ -0,0 +1,89 @@
package com.muyu.cargateway.cargatewaytest;
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.models.RuntimeOptions;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
/**
* @ ToolIntelliJ IDEA
* @ AuthorCHX
* @ Date2024-09-28-21:20
* @ Version1.0
* @ Description
* @author Lenovo
*/
@Log4j2
@Component
public class DeleteSample implements DisposableBean {
public static Client createClient() throws Exception {
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
Config config = new Config()
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
.setAccessKeyId("LTAI5tDH3FyRx4PRr6anx2TL")
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
.setAccessKeySecret("xdQnX2tDattY50raNkUWmHzE2tondP");
// Endpoint 请参考 https://api.aliyun.com/product/Ecs
config.endpoint = "ecs-cn-hangzhou.aliyuncs.com";
return new Client(config);
}
public static void deleteSample() throws Exception {
Client client = DeleteSample.createClient();
DescribeInstancesRequest attributeRequest = new DescribeInstancesRequest();
attributeRequest.setRegionId("cn-shanghai");
RuntimeOptions runtimeOptions = new RuntimeOptions();
DescribeInstancesResponse instancesWithOptions = client.describeInstancesWithOptions(attributeRequest, runtimeOptions);
ArrayList<String> list = new ArrayList<>();
DescribeInstancesResponseBody body = instancesWithOptions.getBody();
for (DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance instance : body.instances.instance) {
list.add(instance.getInstanceId());
}
log.info("list:"+list);
DeleteInstancesRequest deleteInstancesRequest = new DeleteInstancesRequest();
deleteInstancesRequest.setRegionId("cn-shanghai")
.setDryRun(false)
.setForce(true)
.setTerminateSubscription(true)
.setInstanceId(list);
RuntimeOptions runtime = new RuntimeOptions();
try{
client.deleteInstancesWithOptions(deleteInstancesRequest, runtime);
}catch (TeaException error) {
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
// 错误 message
System.out.println(error.getMessage());
// 诊断地址
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
} catch (Exception _error) {
TeaException error = new TeaException(_error.getMessage(), _error);
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
// 错误 message
System.out.println(error.getMessage());
// 诊断地址
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
}
}
@Override
public void destroy(){
try {
log.info("删除实例方法");
deleteSample();
} catch (Exception e) {
log.info("删除实例失败");
throw new RuntimeException(e);
}
log.info("删除实例成功");
}
}

View File

@ -0,0 +1,107 @@
package com.muyu.cargateway.cargatewaytest;
import com.aliyun.ecs20140526.Client;
import com.aliyun.ecs20140526.models.RunInstancesRequest;
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.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
/**
* @ ToolIntelliJ IDEA
* @ AuthorCHX
* @ Date2024-09-28-21:10
* @ Version1.0
* @ Descriptionali
* @author Lenovo
*/
@Log4j2
@Component
public class Sample implements ApplicationRunner {
public static Client createClient() throws Exception {
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
Config config = new Config()
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
.setAccessKeyId("LTAI5tDH3FyRx4PRr6anx2TL")
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
.setAccessKeySecret("xdQnX2tDattY50raNkUWmHzE2tondP");
// Endpoint 请参考 https://api.aliyun.com/product/Ecs
config.endpoint = "ecs-cn-hangzhou.aliyuncs.com";
return new Client(config);
}
public static void generateInstance() throws Exception {
Client client = Sample.createClient();
RunInstancesRequest.RunInstancesRequestSystemDisk systemDisk = new RunInstancesRequest.RunInstancesRequestSystemDisk();
//设置系统盘的大小为40GiB
systemDisk.setSize("40");
//设置系统盘类型为cloud_essd
systemDisk.setCategory("cloud_essd");
// 创建创建实例请求对象并设置参数
RunInstancesRequest runInstancesRequest = new RunInstancesRequest()
// 设置地域ID
.setRegionId("cn-shanghai")
// 设置镜像ID
.setImageId("m-uf65fvle9qseu9jo5jl3")
// 设置实例规格类型
.setInstanceType("ecs.t6-c1m1.large")
// 设置安全组ID
.setSecurityGroupId("sg-uf642d5u4ja5gsiitx8y")
// 设置虚拟交换机ID
.setVSwitchId("vsw-uf66lifrkhxqc94xi06v3")
// 设置实例名称
.setInstanceName("server-mqtt")
// 设置付费类型 按量付费
.setInstanceChargeType("PostPaid")
// 设置系统盘配置
.setSystemDisk(systemDisk)
// 设置用户名
.setHostName("root")
// 设置密码
.setPassword("10160810@a")
// 设置要创创建的实例数量
.setAmount(1)
.setInternetChargeType("PayByTraffic")
.setInternetMaxBandwidthOut(1);
RuntimeOptions runtimeOptions = new RuntimeOptions();
// 尝试执行创建实例请求
try {
// 复制代码运行请自行打印 API 的返回值
client.runInstancesWithOptions(runInstancesRequest, runtimeOptions);
} catch (TeaException error) {
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
// 错误 message
System.out.println(error.getMessage());
// 诊断地址
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
} catch (Exception _error) {
TeaException error = new TeaException(_error.getMessage(), _error);
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
// 错误 message
System.out.println(error.getMessage());
// 诊断地址
System.out.println(error.getData().get("Recommend"));
Common.assertAsString(error.message);
}
}
@Override
public void run(ApplicationArguments args){
try {
log.info("开始创建实例");
generateInstance();
} catch (Exception e) {
log.info("创建实例失败");
throw new RuntimeException(e);
}
log.info("创建实例成功");
}
}

View File

@ -0,0 +1,27 @@
package com.muyu.cargateway.controller;
import com.muyu.cargateway.service.CarOneClickOperationService;
import com.muyu.common.core.domain.Result;
import lombok.extern.log4j.Log4j2;
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.RestController;
/**
* @ ToolIntelliJ IDEA
* @ AuthorCHX
* @ Date2024-09-26-20:14
* @ Version1.0
* @ Description
* @author Lenovo
*/
@Log4j2
@RestController
@RequestMapping("/car/oneClick")
public class CarOneClickOperationController {
@Autowired
private CarOneClickOperationService carOneClickOperationService;
}

View File

@ -0,0 +1,64 @@
package com.muyu.cargateway.controller;
import com.muyu.cargateway.service.CarOneClickOperationService;
import lombok.extern.log4j.Log4j2;
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.RestController;
/**
* @ ToolIntelliJ IDEA
* @ AuthorCHX
* @ Date2024-09-27-20:08
* @ Version1.0
* @ Descriptionfluxmq
* @author Lenovo
*/
@Log4j2
@RestController
@RequestMapping("/testCarGateway")
public class TestController {
@PostMapping("/testCarConnect")
public void testCarConnect() {
String topic="carOneClick";
String message="{\"carId\":\"123456789\",\"operation\":\"turnOn\"}";;
String broker="tcp://106.54.193.225:1883";
String clientId="javaSample";
int qos=1;
try {
MqttClient mqttClient =new MqttClient(broker, clientId);
MqttConnectOptions mqttConnectOptions = new MqttConnectOptions();
mqttConnectOptions.setCleanSession(true);
log.info("连接成功"+broker);
mqttClient.connect(mqttConnectOptions);
mqttClient.subscribe(topic,0);
mqttClient.setCallback(new MqttCallback() {
@Override
public void connectionLost(Throwable throwable) {
log.info("连接丢失");
}
@Override
public void messageArrived(String s, MqttMessage mqttMessage) throws Exception {
log.info(new String(mqttMessage.getPayload()));
}
@Override
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
//发布完成时调用
}
});
} catch (MqttException e) {
log.info("连接失败"+e.getReasonCode());
log.info("信息"+e.getMessage());
log.info("异常"+e);
log.info("异常信息"+e.getLocalizedMessage());
log.info("异常类型"+e.getClass());
e.printStackTrace();
throw new RuntimeException(e);
}
}
}

View File

@ -0,0 +1,46 @@
package com.muyu.cargateway.domain;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @ ToolIntelliJ IDEA
* @ AuthorCHX
* @ Date2024-09-28-16:37
* @ Version1.0
* @ Description
* @author Lenovo
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class AliServerConfig {
/**
*
*/
private Long id;
/**
* ID
*/
private String regionId;
/**
* ID
*/
private String imageId;
/**
*
*/
private String instanceType;
/**
* ID
*/
private String securityGroupId;
/**
* ID
*/
private String vSwitchId;
}

View File

@ -0,0 +1,58 @@
package com.muyu.cargateway.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @ ToolIntelliJ IDEA
* @ AuthorCHX
* @ Date2024-09-27-20:56
* @ Version1.0
* @ Description
* @author Lenovo
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName(value="server_config")
public class ServerConfig {
/**
*
*/
@TableId(value = "id",type = IdType.AUTO)
private Long id;
/**
* id
*/
private String tenantId;
/**
*
*/
private String host;
/**
*
*/
private String port;
/**
*
*/
private String uri;
/**
* MQTT
*/
private String defaultMqttAddr;
/**
* MQTT
*/
private String defaultMqttTopic;
/**
* MQTT QOS
*/
private Integer defaultMqttQos;
}

View File

@ -0,0 +1,87 @@
package com.muyu.cargateway.domain.model;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.log4j.Log4j2;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @ ToolIntelliJ IDEA
* @ AuthorCHX
* @ Date2024-09-26-20:23
* @ Version1.0
* @ Description
* @author Lenovo
*/
@Data
@Log4j2
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class TaskModel {
/**
* false
* truefalse
*/
private final AtomicBoolean status =new AtomicBoolean(Boolean.FALSE);
/**
*
*/
private CountDownLatch countDownLatch;
/**
*
*/
private LinkedBlockingDeque<String> carQueue =new LinkedBlockingDeque<>();
/**
*
* true
* false
* @return
*/
private boolean isExecution(){
return !status.get();
}
/**
*
*/
private String taskName;
/**
*
*/
private Integer taskExecutionCount=0;
/**
*
*/
private Long taskStartTime;
/**
*
*/
private AtomicInteger taskSuccessSum=new AtomicInteger();
/**
*
*/
private AtomicInteger taskErrorSum=new AtomicInteger();
/**
*
* @return true
*/
public boolean hashNext(){
return !carQueue.isEmpty();
}
/**
*
* @return VIN
*/
public String next(){
return carQueue.poll();
}
}

View File

@ -0,0 +1,45 @@
package com.muyu.cargateway.domain.properties;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author Lenovo
* @ ToolIntelliJ IDEA
* @ AuthorCHX
* @ Date2024-09-26-22:13
* @ Version1.0
* @ DescriptionMqtt
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class MqttProperties {
/**
*
*/
private String broker;
/**
*
*/
private String topic;
/**
*
*/
private String userName;
/**
*
*/
private String password;
/**
* id
*/
private String clientId;
/**
*
*/
private int qos = 0;
}

View File

@ -0,0 +1,37 @@
package com.muyu.cargateway.domain.resp;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
* @ ToolIntelliJ IDEA
* @ AuthorCHX
* @ Date2024-09-26-15:53
* @ Version1.0
* @ DescriptionAli
* @author Lenovo
*/
@Data
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
public class AliServerConfig {
/**
*
*/
private Long id;
/**
* id (ID)
*/
private String regionId;
/**
* id
*/
private String imageId;
/**
* ()
*/
private String instanceType;
}

View File

@ -0,0 +1,15 @@
package com.muyu.cargateway.mapper;
import org.apache.ibatis.annotations.Mapper;
/**
* @ ToolIntelliJ IDEA
* @ AuthorCHX
* @ Date2024-09-26-20:15
* @ Version1.0
* @ Description
* @author Lenovo
*/
@Mapper
public interface CarOneClickOperationMapper {
}

View File

@ -0,0 +1,14 @@
package com.muyu.cargateway.service;
/**
* @ ToolIntelliJ IDEA
* @ AuthorCHX
* @ Date2024-09-26-20:15
* @ Version1.0
* @ Description
* @author Lenovo
*/
public interface CarOneClickOperationService {
}

View File

@ -0,0 +1,18 @@
package com.muyu.cargateway.service.Impl;
import com.muyu.cargateway.service.CarOneClickOperationService;
import org.springframework.stereotype.Service;
/**
* @ ToolIntelliJ IDEA
* @ AuthorCHX
* @ Date2024-09-26-20:16
* @ Version1.0
* @ Description
* @author Lenovo
*/
@Service
public class CarOneClickOperationServiceImpl implements CarOneClickOperationService {
}

View File

@ -0,0 +1,60 @@
//package com.muyu.cargateway.test;
//
//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.MqttMessage;
//
///**
// * @ ToolIntelliJ IDEA
// * @ AuthorCHX
// * @ Date2024-09-27-22:32
// * @ Version1.0
// * @ Descriptionmqtt
// * @author Lenovo
// */
//@Log4j2
//public class MqttPublisher {
// //MQTT代理地址
// String broker="tcp://106.54.193.225:1883";
// //客户端ID
// String clientId="car-gateway";
// //主题
// String topic="car-gateway";
// //要发送的内容
// String content="连接成功";
// //服务质量 0:最多一次 1:至少一次 2:
// int qos=0;
// MqttClient mqttClient;
//
// {
// try {
// mqttClient = new MqttClient(broker, clientId);
//
// //连接到MQtt代理
// MqttConnectOptions mqttConnectOptions = new MqttConnectOptions();
// //清空会话
// mqttConnectOptions.setCleanSession(true);
// //连接
// mqttClient.connect(mqttConnectOptions);
// log.info("MQTT客户端连接成功"+broker);
//
// //发送消息
// MqttMessage message = new MqttMessage(content.getBytes());
// //设置服务的质量
// message.setQos(qos);
// //开始发送消息
// mqttClient.publish(topic, message);
// log.info("消息发送成功,消息是:"+content);
//
// //断开连接
// mqttClient.disconnect();
// log.info("MQTT断开连接成功");
// } catch (MqttException e) {
// //输出异常信息
// e.getStackTrace();
// throw new RuntimeException(e);
// }
// }
//}

View File

@ -0,0 +1,120 @@
//package com.muyu.cargateway.test;
//
//import com.aliyun.ecs20140526.Client;
//import com.aliyun.ecs20140526.models.RunInstancesRequest;
//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 java.util.Arrays;
//import java.util.List;
//
//
///**
// * @ ToolIntelliJ IDEA
// * @ AuthorCHX
// * @ Date2024-09-27-23:38
// * @ Version1.0
// * @ Description调用ali的测试demo类
// * @author Lenovo
// */
//@Log4j2
//public class Sample {
//
// /**
// * <b>description</b> :
// * <p>使用AK&amp;SK初始化账号Client</p>
// * @return Client
// *
// * @throws Exception
// */
// public static Client createClient() throws Exception {
// // 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
// Config config = new Config()
// // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
// .setAccessKeyId("LTAI5tDH3FyRx4PRr6anx2TL")
// // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
// .setAccessKeySecret("xdQnX2tDattY50raNkUWmHzE2tondP");
// // Endpoint 请参考 https://api.aliyun.com/product/Ecs
// config.endpoint = "ecs-cn-hangzhou.aliyuncs.com";
// return new Client(config);
// }
//
// /**
// * 本程序的入口点
// * 主要功能是创建阿里云ECS实例
// *
// * @param args 命令行参数
// * @throws Exception 如果执行过程中发生错误则抛出异常
// */
// public static void main(String[] args) throws Exception {
// // 将命令行参数转换为字符串列表
// List<String> arg = Arrays.asList(args);
//
// // 创建阿里云ECS客户端
// Client client = Sample.createClient();
//
// // 配置系统盘参数
// RunInstancesRequest.RunInstancesRequestSystemDisk systemDisk = new RunInstancesRequest.RunInstancesRequestSystemDisk()
// // 设置系统盘大小为20G
// .setSize("40")
// // 设置系统盘类型为cloud_essd
// .setCategory("cloud_essd");
//
// // 创建创建实例请求对象并设置参数
//
// RunInstancesRequest runInstancesRequest = new RunInstancesRequest()
// // 设置地域ID
// .setRegionId("cn-shanghai")
// // 设置镜像ID
// .setImageId("m-uf65fvle9qseu9jo5jl3")
// // 设置实例规格类型
// .setInstanceType("ecs.t6-c1m1.large")
// // 设置安全组ID
// .setSecurityGroupId("sg-uf642d5u4ja5gsiitx8y")
// // 设置虚拟交换机ID
// .setVSwitchId("vsw-uf66lifrkhxqc94xi06v3")
// // 设置实例名称
// .setInstanceName("server-mqtt")
// // 设置付费类型 按量付费
// .setInstanceChargeType("PostPaid")
// // 设置系统盘配置
// .setSystemDisk(systemDisk)
// // 设置用户名
// .setHostName("root")
// // 设置密码
// .setPassword("10160810@a")
// // 设置要创创建的实例数量
// .setAmount(1);
//
//
//
//
// // 创建运行时选项对象
// RuntimeOptions runtime = new RuntimeOptions();
//
// // 尝试执行创建实例请求
// try {
// // 复制代码运行请自行打印 API 的返回值
// client.runInstancesWithOptions(runInstancesRequest, runtime);
// } catch (TeaException error) {
// // 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
// // 错误 message
// System.out.println(error.getMessage());
// // 诊断地址
// System.out.println(error.getData().get("Recommend"));
// com.aliyun.teautil.Common.assertAsString(error.message);
// } catch (Exception _error) {
// TeaException error = new TeaException(_error.getMessage(), _error);
// // 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
// // 错误 message
// System.out.println(error.getMessage());
// // 诊断地址
// System.out.println(error.getData().get("Recommend"));
// Common.assertAsString(error.message);
// }
// }
//}
//

View File

@ -0,0 +1,2 @@
Spring Boot Version: ${spring-boot.version}
Spring Application Name: ${spring.application.name}

View File

@ -0,0 +1,60 @@
# Tomcat
server:
port: 9702
# nacos线上地址
nacos:
addr: 106.54.193.225:8848
user-name: nacos
password: nacos
namespace: one
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
# Spring
spring:
amqp:
deserialization:
trust:
all: true
main:
allow-bean-definition-overriding: true
application:
# 应用名称
name: cloud-breakdown
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}
# xxl-job 配置文件
- application-xxl-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
# rabbit 配置文件
- application-rabbit-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
logging:
level:
com.muyu.breakdown.mapper: DEBUG

View File

@ -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-breakdown"/>
<!-- 日志输出格式 -->
<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>

View File

@ -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-breakdown"/>
<!-- 日志输出格式 -->
<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>

View File

@ -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-breakdown"/>
<!-- 日志输出格式 -->
<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>

View File

@ -4,7 +4,7 @@ server:
# nacos线上地址 # nacos线上地址
nacos: nacos:
addr: 127.0.0.1:8848 addr: 106.54.193.225:8848
user-name: nacos user-name: nacos
password: nacos password: nacos
namespace: public namespace: public

View File

@ -4,7 +4,7 @@ server:
# nacos线上地址 # nacos线上地址
nacos: nacos:
addr: 127.0.0.1:8848 addr: 47.116.173.119:8848
user-name: nacos user-name: nacos
password: nacos password: nacos
namespace: one-saas namespace: one-saas

View File

@ -4,7 +4,7 @@ server:
# nacos线上地址 # nacos线上地址
nacos: nacos:
addr: 127.0.0.1:8848 addr: 47.116.173.119:8848
user-name: nacos user-name: nacos
password: nacos password: nacos
namespace: one-saas namespace: one-saas

View File

@ -4,7 +4,7 @@ server:
# nacos线上地址 # nacos线上地址
nacos: nacos:
addr: 127.0.0.1:8848 addr: 47.116.173.119:8848
user-name: nacos user-name: nacos
password: nacos password: nacos
namespace: one-saas namespace: one-saas

View File

@ -4,7 +4,7 @@ server:
# nacos线上地址 # nacos线上地址
nacos: nacos:
addr: 127.0.0.1:8848 addr: 47.116.173.119:8848
user-name: nacos user-name: nacos
password: nacos password: nacos
namespace: one-saas namespace: one-saas

View File

@ -4,7 +4,7 @@ server:
# nacos线上地址 # nacos线上地址
nacos: nacos:
addr: 127.0.0.1:8848 addr: 106.54.193.225:8848
user-name: nacos user-name: nacos
password: nacos password: nacos
namespace: one namespace: one

View File

@ -18,6 +18,7 @@
<module>cloud-modules-rail</module> <module>cloud-modules-rail</module>
<module>cloud-modules-warn</module> <module>cloud-modules-warn</module>
<module>cloud-modules-carmanage</module> <module>cloud-modules-carmanage</module>
<module>cloud-modules-car-gateway</module>
</modules> </modules>
<artifactId>cloud-modules</artifactId> <artifactId>cloud-modules</artifactId>

View File

@ -4,7 +4,7 @@ server:
# nacos线上地址 # nacos线上地址
nacos: nacos:
addr: 127.0.0.1:8848 addr: 106.54.193.225:8848
user-name: nacos user-name: nacos
password: nacos password: nacos
namespace: one-saas namespace: one-saas

View File

@ -639,8 +639,8 @@ CREATE TABLE `sys_user` (
-- Records of sys_user -- Records of sys_user
-- ---------------------------- -- ----------------------------
BEGIN; BEGIN;
INSERT INTO `sys_user` (`user_id`, `dept_id`, `user_name`, `nick_name`, `user_type`, `email`, `phonenumber`, `sex`, `avatar`, `password`, `status`, `del_flag`, `login_ip`, `login_date`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES (1, 103, 'admin', '若依', '00', 'ry@163.com', '15888888888', '1', '', '$2a$10$7JB720yubVSZvUI0rEqK/.VqGOZTH.ulu33dHOiBE8ByOhJIrdAu2', '0', '0', '127.0.0.1', '2024-05-23 15:08:18', 'admin', '2024-05-23 15:08:18', '', NULL, '管理员'); INSERT INTO `sys_user` (`user_id`, `dept_id`, `user_name`, `nick_name`, `user_type`, `email`, `phonenumber`, `sex`, `avatar`, `password`, `status`, `del_flag`, `login_ip`, `login_date`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES (1, 103, 'admin', '若依', '00', 'ry@163.com', '15888888888', '1', '', '$2a$10$7JB720yubVSZvUI0rEqK/.VqGOZTH.ulu33dHOiBE8ByOhJIrdAu2', '0', '0', '106.54.193.225', '2024-05-23 15:08:18', 'admin', '2024-05-23 15:08:18', '', NULL, '管理员');
INSERT INTO `sys_user` (`user_id`, `dept_id`, `user_name`, `nick_name`, `user_type`, `email`, `phonenumber`, `sex`, `avatar`, `password`, `status`, `del_flag`, `login_ip`, `login_date`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES (2, 105, 'ry', '若依', '00', 'ry@qq.com', '15666666666', '1', '', '$2a$10$7JB720yubVSZvUI0rEqK/.VqGOZTH.ulu33dHOiBE8ByOhJIrdAu2', '0', '0', '127.0.0.1', '2024-05-23 15:08:18', 'admin', '2024-05-23 15:08:18', '', NULL, '测试员'); INSERT INTO `sys_user` (`user_id`, `dept_id`, `user_name`, `nick_name`, `user_type`, `email`, `phonenumber`, `sex`, `avatar`, `password`, `status`, `del_flag`, `login_ip`, `login_date`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES (2, 105, 'ry', '若依', '00', 'ry@qq.com', '15666666666', '1', '', '$2a$10$7JB720yubVSZvUI0rEqK/.VqGOZTH.ulu33dHOiBE8ByOhJIrdAu2', '0', '0', '106.54.193.225', '2024-05-23 15:08:18', 'admin', '2024-05-23 15:08:18', '', NULL, '测试员');
COMMIT; COMMIT;
-- ---------------------------- -- ----------------------------