优化更新:历史轨迹-调用阿里云创建实例
parent
a25d60ba4d
commit
8acc307211
|
@ -0,0 +1,273 @@
|
|||
<?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>muyu</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
<properties>
|
||||
<maven.compiler.source>20</maven.compiler.source>
|
||||
<maven.compiler.target>20</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
|
||||
|
||||
|
||||
<artifactId>aliyun-api</artifactId>
|
||||
|
||||
<groupId>com.aliyun</groupId>
|
||||
|
||||
<version>1.0.0</version>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>sample</name>
|
||||
<description>Alibaba Cloud SDK Code Sample for Java
|
||||
</description>
|
||||
<url>https://github.com/aliyun/alibabacloud-code-sample</url>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>The Apache License, Version 2.0</name>
|
||||
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
||||
</license>
|
||||
</licenses>
|
||||
<developers>
|
||||
<developer>
|
||||
<id>aliyundeveloper</id>
|
||||
<name>Aliyun SDK</name>
|
||||
<email>aliyunsdk@aliyun.com</email>
|
||||
</developer>
|
||||
</developers>
|
||||
<distributionManagement>
|
||||
<snapshotRepository>
|
||||
<id>sonatype-nexus-snapshots</id>
|
||||
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
|
||||
</snapshotRepository>
|
||||
<repository>
|
||||
<id>sonatype-nexus-staging</id>
|
||||
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
<scm>
|
||||
<connection></connection>
|
||||
<developerConnection></developerConnection>
|
||||
<url></url>
|
||||
</scm>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>ecs20140526</artifactId>
|
||||
<version>3.1.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>tea-openapi</artifactId>
|
||||
<version>0.3.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>tea-util</artifactId>
|
||||
<version>0.2.21</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>tea-console</artifactId>
|
||||
<version>0.0.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>darabonba-env</artifactId>
|
||||
<version>0.1.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>tea</artifactId>
|
||||
<version>1.1.14</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-core</artifactId>
|
||||
</dependency>
|
||||
<!-- 引入swagger-->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-boot-starter</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</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>
|
||||
|
||||
<!-- Swagger UI -->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>${swagger.fox.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Mysql Connector -->
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- RuoYi Common DataSource -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-datasource</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- RuoYi Common DataScope -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-datascope</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- RuoYi Common Log -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-log</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- RuoYi Common Swagger -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-swagger</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-file-remote</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.paho</groupId>
|
||||
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
|
||||
<version>1.2.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-event</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.6.1</version>
|
||||
<configuration>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
<version>1.6</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>sign-artifacts</id>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>sign</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.sonatype.plugins</groupId>
|
||||
<artifactId>nexus-staging-maven-plugin</artifactId>
|
||||
<version>1.6.3</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<serverId>sonatype-nexus-staging</serverId>
|
||||
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
|
||||
<autoReleaseAfterClose>true</autoReleaseAfterClose>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.1.1</version>
|
||||
<configuration>
|
||||
<encoding>UTF-8</encoding>
|
||||
<doclint>none</doclint>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>2.4.1</version>
|
||||
<configuration>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
<archive>
|
||||
<manifest>
|
||||
<addClasspath>true</addClasspath>
|
||||
<mainClass>com.aliyun.sample.Sample1</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>make-assembly</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
|
||||
</build>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</project>
|
|
@ -0,0 +1,31 @@
|
|||
package com.aliyun.demo.config;
|
||||
|
||||
/**
|
||||
* @BelongsProject: com.aliyun.demo
|
||||
* @BelongsPackage: com.aliyun.demo.config
|
||||
* @Author: HuangDaJu
|
||||
* @CreateTime: 2024-04-11 22:10
|
||||
* @Description: 阿里云客户端配置类
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class ClientConfig {
|
||||
|
||||
/**
|
||||
* 使用AK&SK初始化账号Client
|
||||
* @return Client
|
||||
* @throws Exception
|
||||
*/
|
||||
public static com.aliyun.ecs20140526.Client createClient() throws Exception {
|
||||
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
|
||||
// 建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378657.html。
|
||||
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
|
||||
.setAccessKeyId("LTAI5tANGefs2gi8nsu4AoSZ")
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
|
||||
.setAccessKeySecret("Ut5RaJvvG7dP8hgK82qjdtvyUA6x8g");
|
||||
// Endpoint 请参考 https://api.aliyun.com/product/Ecs
|
||||
config.endpoint = "ecs.cn-zhangjiakou.aliyuncs.com";
|
||||
return new com.aliyun.ecs20140526.Client(config);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
package com.aliyun.demo.create;
|
||||
|
||||
import com.aliyun.demo.config.ClientConfig;
|
||||
import com.aliyun.ecs20140526.models.CreateInstanceResponse;
|
||||
import com.aliyun.ecs20140526.models.CreateInstanceResponseBody;
|
||||
import com.aliyun.tea.TeaException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 创建一台或多台按量收费的ECS实例。
|
||||
*
|
||||
* @BelongsProject: aliyun-api
|
||||
* @BelongsPackage: com.aliyun.demo.create
|
||||
* @Author: HuangDaJu
|
||||
* @CreateTime: 2024-04-11 21:23
|
||||
* @Description: 主要用于创建ECS实例的示例代码。
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class CreateServer {
|
||||
|
||||
/**
|
||||
* 主函数入口。
|
||||
* @throws Exception 可能抛出的异常。
|
||||
*/
|
||||
public static void main(String[] args_) throws Exception {
|
||||
List<String> args = java.util.Arrays.asList(args_); // 将命令行参数转换为List<String>格式
|
||||
com.aliyun.ecs20140526.Client client = ClientConfig.createClient(); // 创建ECS客户端
|
||||
|
||||
// 设置系统盘参数
|
||||
com.aliyun.ecs20140526.models.CreateInstanceRequest.CreateInstanceRequestSystemDisk systemDisk =
|
||||
new com.aliyun.ecs20140526.models.CreateInstanceRequest.CreateInstanceRequestSystemDisk()
|
||||
.setCategory("cloud_efficiency")
|
||||
.setSize(20);
|
||||
|
||||
// 创建实例请求对象,并设置相关参数
|
||||
com.aliyun.ecs20140526.models.CreateInstanceRequest createInstanceRequest =
|
||||
new com.aliyun.ecs20140526.models.CreateInstanceRequest()
|
||||
.setRegionId("cn-zhangjiakou") // 地域ID
|
||||
.setImageId("m-8vb8z0ygyrzgqt54k3wi") // 镜像ID
|
||||
.setInstanceType("ecs.t6-c1m1.large") // 实例规格
|
||||
.setSecurityGroupId("sg-8vbfx0e48cekrpzgsa72") // 安全组ID
|
||||
.setInstanceName("huangdaju-hdj") // 实例名称
|
||||
.setInternetChargeType("PayByTraffic") // 上网计费方式
|
||||
.setAutoRenew(false) // 是否自动续费
|
||||
.setInternetMaxBandwidthIn(5) // 公网入带宽最大值
|
||||
.setInternetMaxBandwidthOut(5) // 公网出带宽最大值
|
||||
.setPassword("Huangdaju520.") // 实例密码
|
||||
.setZoneId("cn-zhangjiakou-c") // 可用区ID
|
||||
.setSystemDisk(systemDisk) // 系统盘设置
|
||||
.setVSwitchId("vsw-8vbn6cq2uy0mmw69l6ryq") // 交换机ID
|
||||
.setPrivateIpAddress("10.101.0.1") // 私网IP地址
|
||||
.setPeriod(1) // 购买资源的时长
|
||||
.setPeriodUnit("Month") // 购买资源的时长单位
|
||||
.setCreditSpecification("Standard") // 性能模式
|
||||
.setDeletionProtection(false); // 是否开启删除保护
|
||||
|
||||
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions(); // 创建运行时选项
|
||||
|
||||
try {
|
||||
// 发起创建实例的请求,并处理响应
|
||||
CreateInstanceResponse instanceWithOptions = client.createInstanceWithOptions(createInstanceRequest, runtime);
|
||||
Integer statusCode = instanceWithOptions.getStatusCode(); // 获取状态码
|
||||
CreateInstanceResponseBody body = instanceWithOptions.getBody(); // 获取响应体
|
||||
String instanceId = body.getInstanceId(); // 获取实例ID
|
||||
System.out.println("创建返回码:" + statusCode);
|
||||
System.out.println("创建的实例ID:" + instanceId);
|
||||
} catch (TeaException error) {
|
||||
// 处理ECS客户端抛出的异常
|
||||
// 打印异常信息和推荐的诊断地址
|
||||
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);
|
||||
System.out.println(error.getMessage());
|
||||
System.out.println(error.getData().get("Recommend"));
|
||||
com.aliyun.teautil.Common.assertAsString(error.message);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
package com.aliyun.demo.query;
|
||||
|
||||
import com.aliyun.demo.config.ClientConfig;
|
||||
import com.aliyun.ecs20140526.models.DescribeInstancesResponse;
|
||||
import com.aliyun.ecs20140526.models.DescribeInstancesResponseBody;
|
||||
import com.aliyun.tea.TeaException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @BelongsProject: aliyun-api
|
||||
* @BelongsPackage: com.aliyun.demo.query
|
||||
* @Author: HuangDaJu
|
||||
* @CreateTime: 2024-04-11 22:20
|
||||
* @Description: 查询一台或多台ECS实例的详细信息
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class SelectServerInfo {
|
||||
|
||||
static int i = 1;
|
||||
|
||||
public static void main(String[] args_) throws Exception {
|
||||
List<String> args = java.util.Arrays.asList(args_);
|
||||
com.aliyun.ecs20140526.Client client = ClientConfig.createClient();
|
||||
com.aliyun.ecs20140526.models.DescribeInstancesRequest describeInstancesRequest = new com.aliyun.ecs20140526.models.DescribeInstancesRequest()
|
||||
.setRegionId("cn-zhangjiakou")
|
||||
.setInstanceName("huangdaju-hdj")
|
||||
.setPageSize(10);
|
||||
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
|
||||
try {
|
||||
// 复制代码运行请自行打印 API 的返回值
|
||||
DescribeInstancesResponse describeInstancesResponse = client.describeInstancesWithOptions(describeInstancesRequest, runtime);
|
||||
DescribeInstancesResponseBody body = describeInstancesResponse.getBody();
|
||||
DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstances instances = body.getInstances();
|
||||
List<DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance> instance = instances.getInstance();
|
||||
instance.stream().forEach(item->{
|
||||
System.out.println("实例{" + i + "}的ID:" + item.getInstanceId());
|
||||
System.out.println("名称:" + item.getInstanceName());
|
||||
System.out.println("地域ID:" + item.getRegionId());
|
||||
System.out.println("状态:" + item.getStatus());
|
||||
System.out.println("类型:" + item.getInstanceType());
|
||||
System.out.println("CPU核心数:" + item.getCpu());
|
||||
System.out.println("内存大小:" + item.getMemory() + "MB");
|
||||
System.out.println("磁盘大小:" + item.getLocalStorageCapacity() + "G");
|
||||
System.out.println("操作系统:" + item.getOSName());
|
||||
System.out.println("网络类型:" + item.getInstanceNetworkType());
|
||||
System.out.println("公网出带宽值:" + item.getInternetMaxBandwidthOut() + "Mbit/s");
|
||||
System.out.println("公网入带宽值:" + item.getInternetMaxBandwidthIn() + "Mbit/s");
|
||||
System.out.println("公网IP:" + item.getPublicIpAddress().getIpAddress());
|
||||
System.out.println("私网IP:" + item.getVpcAttributes().getPrivateIpAddress().ipAddress);
|
||||
System.out.println("专有网络VPCID:" + item.getVpcAttributes().getVpcId());
|
||||
System.out.println("安全组ID:" + item.getSecurityGroupIds().getSecurityGroupId());
|
||||
System.out.println("创建时间:" + item.getCreationTime());
|
||||
System.out.println("到期时间:" + item.getExpiredTime());
|
||||
System.out.println("是否可以回收:" + (item.getRecyclable()?"是":"否") + "\n\n");
|
||||
i++;
|
||||
|
||||
});
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
// This file is auto-generated, don't edit it. Thanks.
|
||||
package com.aliyun.sample;
|
||||
|
||||
import com.aliyun.tea.*;
|
||||
|
||||
public class Sample {
|
||||
|
||||
/**
|
||||
* 使用AK&SK初始化账号Client
|
||||
* @return Client
|
||||
* @throws Exception
|
||||
*/
|
||||
public static com.aliyun.ecs20140526.Client createClient() throws Exception {
|
||||
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
|
||||
// 建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378657.html。
|
||||
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
|
||||
.setAccessKeyId(System.getenv("LTAI5tANGefs2gi8nsu4AoSZ"))
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
|
||||
.setAccessKeySecret(System.getenv("Ut5RaJvvG7dP8hgK82qjdtvyUA6x8g"));
|
||||
// Endpoint 请参考 https://api.aliyun.com/product/Ecs
|
||||
config.endpoint = "ecs.cn-zhangjiakou.aliyuncs.com";
|
||||
return new com.aliyun.ecs20140526.Client(config);
|
||||
}
|
||||
|
||||
public static void main(String[] args_) throws Exception {
|
||||
java.util.List<String> args = java.util.Arrays.asList(args_);
|
||||
com.aliyun.ecs20140526.Client client = Sample.createClient();
|
||||
com.aliyun.ecs20140526.models.RunInstancesRequest.RunInstancesRequestCpuOptions cpuOptions = new com.aliyun.ecs20140526.models.RunInstancesRequest.RunInstancesRequestCpuOptions()
|
||||
.setCore(2)
|
||||
.setThreadsPerCore(2);
|
||||
com.aliyun.ecs20140526.models.RunInstancesRequest.RunInstancesRequestSystemDisk systemDisk = new com.aliyun.ecs20140526.models.RunInstancesRequest.RunInstancesRequestSystemDisk()
|
||||
.setSize("20")
|
||||
.setCategory("cloud_efficiency")
|
||||
.setPerformanceLevel("PL0");
|
||||
com.aliyun.ecs20140526.models.RunInstancesRequest runInstancesRequest = new com.aliyun.ecs20140526.models.RunInstancesRequest()
|
||||
.setRegionId("cn-zhangjiakou")
|
||||
.setImageId("m-8vb8z0ygyrzgqt54k3wi")
|
||||
.setInstanceType("ecs.e-c1m1.large")
|
||||
.setInternetMaxBandwidthIn(5)
|
||||
.setSystemDisk(systemDisk)
|
||||
.setInternetChargeType("PayByTraffic")
|
||||
.setZoneId("cn-zhangjiakou-c")
|
||||
.setPassword("Huangdaju520.")
|
||||
.setPeriodUnit("Week")
|
||||
.setPeriod(1)
|
||||
.setDryRun(false)
|
||||
.setSecurityEnhancementStrategy("Deactive")
|
||||
.setAmount(1)
|
||||
.setVSwitchId("vsw-8vbn6cq2uy0mmw69l6ryq")
|
||||
.setInstanceName("huandgaju")
|
||||
.setSecurityGroupId("sg-8vbfx0e48cekrpzgsa72")
|
||||
.setPasswordInherit(false)
|
||||
.setUniqueSuffix(false)
|
||||
.setAutoRenew(false)
|
||||
.setInstanceChargeType("PostPaid")
|
||||
.setDeletionProtection(false)
|
||||
.setCpuOptions(cpuOptions);
|
||||
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.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"));
|
||||
com.aliyun.teautil.Common.assertAsString(error.message);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
// This file is auto-generated, don't edit it. Thanks.
|
||||
package com.aliyun.sample;
|
||||
|
||||
import com.aliyun.tea.*;
|
||||
|
||||
public class Sample1 {
|
||||
|
||||
/**
|
||||
* 使用AK&SK初始化账号Client
|
||||
|
||||
* @return Client
|
||||
* @throws Exception
|
||||
*/
|
||||
public static com.aliyun.ecs20140526.Client createClient() throws Exception {
|
||||
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
|
||||
// 建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378657.html。
|
||||
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
|
||||
.setAccessKeyId("LTAI5tANGefs2gi8nsu4AoSZ")
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
|
||||
.setAccessKeySecret("Ut5RaJvvG7dP8hgK82qjdtvyUA6x8g");
|
||||
// Endpoint 请参考 https://api.aliyun.com/product/Ecs
|
||||
config.endpoint = "cn-zhangjiakou";
|
||||
return new com.aliyun.ecs20140526.Client(config);
|
||||
}
|
||||
|
||||
public static void main(String[] args_) throws Exception {
|
||||
// java.util.List<String> args = java.util.Arrays.asList(args_);
|
||||
com.aliyun.ecs20140526.Client client = Sample1.createClient();
|
||||
com.aliyun.ecs20140526.models.DescribeUserDataRequest describeUserDataRequest = new com.aliyun.ecs20140526.models.DescribeUserDataRequest()
|
||||
.setInstanceId("i-8vbamj8u1q8xnmkze5m0");
|
||||
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
|
||||
try {
|
||||
// 复制代码运行请自行打印 API 的返回值
|
||||
client.describeUserDataWithOptions(describeUserDataRequest, 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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
// This file is auto-generated, don't edit it. Thanks.
|
||||
package com.aliyun.sample;
|
||||
|
||||
import com.aliyun.darabonba.env.EnvClient;
|
||||
import com.aliyun.ecs20140526.models.DescribeInstanceMonitorDataRequest;
|
||||
import com.aliyun.ecs20140526.models.DescribeInstanceMonitorDataResponse;
|
||||
import com.aliyun.ecs20140526.models.DescribeUserDataRequest;
|
||||
import com.aliyun.ecs20140526.models.DescribeUserDataResponse;
|
||||
import com.aliyun.tea.TeaException;
|
||||
import com.aliyun.tea.TeaModel;
|
||||
import com.aliyun.teaopenapi.models.Config;
|
||||
import com.aliyun.teautil.Common;
|
||||
|
||||
public class Sample2 {
|
||||
|
||||
/**
|
||||
* Initialization 初始化公共请求参数
|
||||
*/
|
||||
public static com.aliyun.ecs20140526.Client Initialization(String regionId) throws Exception {
|
||||
Config config = new Config();
|
||||
// 您的AccessKey ID
|
||||
config.accessKeyId = EnvClient.getEnv("LTAI5tANGefs2gi8nsu4AoSZ");
|
||||
// 您的AccessKey Secret
|
||||
config.accessKeySecret = EnvClient.getEnv("Ut5RaJvvG7dP8hgK82qjdtvyUA6x8g");
|
||||
// 您的可用区ID
|
||||
config.regionId = regionId;
|
||||
return new com.aliyun.ecs20140526.Client(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* DescribeInstanceMonitorData 查询一台 Ecs 实例所有相关的监控信息
|
||||
*/
|
||||
public static void DescribeInstanceMonitorData(com.aliyun.ecs20140526.Client client, String instanceId, String startTime, String endTime) throws Exception {
|
||||
DescribeInstanceMonitorDataRequest req = new DescribeInstanceMonitorDataRequest();
|
||||
// 待查询的实例 ID
|
||||
req.instanceId = instanceId;
|
||||
// 获取数据的起始时间点。按照 ISO8601 标准表示,并需要使用 UTC 时间,格式为:YYYY-MM-DDThh:mm:ssZ。如果指定的秒(ss)不是 00,则自动换算为下一分钟。
|
||||
req.startTime = startTime;
|
||||
// 获取数据的结束时间点。按照 ISO8601 标准表示,并需要使用 UTC 时间,格式为:YYYY-MM-DDThh:mm:ssZ。 如果指定的秒(ss)不是 00,则自动换算为下一分钟。
|
||||
req.endTime = endTime;
|
||||
try {
|
||||
DescribeInstanceMonitorDataResponse resp = client.describeInstanceMonitorData(req);
|
||||
com.aliyun.teaconsole.Client.log("--------------------查询Ecs所有相关的监控信息--------------------");
|
||||
com.aliyun.teaconsole.Client.log(Common.toJSONString(TeaModel.buildMap(resp)));
|
||||
} catch (TeaException error) {
|
||||
com.aliyun.teaconsole.Client.log(error.message);
|
||||
} catch (Exception _error) {
|
||||
TeaException error = new TeaException(_error.getMessage(), _error);
|
||||
com.aliyun.teaconsole.Client.log(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* DescribeUserData 查询一台Ecs实例的自定义数据
|
||||
*/
|
||||
public static void DescribeUserData(com.aliyun.ecs20140526.Client client, String instanceId, String regionId) throws Exception {
|
||||
DescribeUserDataRequest req = new DescribeUserDataRequest();
|
||||
req.regionId = regionId;
|
||||
req.instanceId = instanceId;
|
||||
try {
|
||||
DescribeUserDataResponse resp = client.describeUserData(req);
|
||||
com.aliyun.teaconsole.Client.log("--------------------查询Ecs自定义数据--------------------");
|
||||
com.aliyun.teaconsole.Client.log(Common.toJSONString(TeaModel.buildMap(resp)));
|
||||
} catch (TeaException error) {
|
||||
com.aliyun.teaconsole.Client.log(error.message);
|
||||
} catch (Exception _error) {
|
||||
TeaException error = new TeaException(_error.getMessage(), _error);
|
||||
com.aliyun.teaconsole.Client.log(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args_) throws Exception {
|
||||
// java.util.List<String> args = java.util.Arrays.asList(args_);
|
||||
// 可用区域Id
|
||||
String regionId = "cn-zhangjiakou";
|
||||
// 待查询的实例 ID
|
||||
String instanceId = "i-8vbamj8u1q8xnmkze5m0";
|
||||
// 获取数据的起始时间点。按照 ISO8601 表示,并需要使用 UTC 时间,格式为:YYYY-MM-DDThh:mm:ssZ。如果指定的秒(ss)不是 00,则自动换算为下一分钟。
|
||||
String startTime = "2024-03-14T12:12:12Z";
|
||||
// 获取数据的结束时间点。按照 ISO8601 标准表示,并需要使用 UTC 时间,格式为:YYYY-MM-DDThh:mm:ssZ。 如果指定的秒(ss)不是 00,则自动换算为下一分钟。
|
||||
String endTime = "2024-04-10T12:12:12Z";
|
||||
com.aliyun.ecs20140526.Client client = Sample2.Initialization(regionId);
|
||||
// 查询一台 Ecs 实例所有相关的监控信息
|
||||
Sample2.DescribeInstanceMonitorData(client, instanceId, startTime, endTime);
|
||||
// 查询一台Ecs实例的自定义数据
|
||||
Sample2.DescribeUserData(client, instanceId, regionId);
|
||||
}
|
||||
}
|
|
@ -107,11 +107,6 @@
|
|||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
|
||||
<!--MQ-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
package com.muyu.analyze.config;
|
||||
|
||||
|
||||
import com.muyu.common.core.constant.*;
|
||||
import org.springframework.amqp.core.*;
|
||||
import org.springframework.context.annotation.*;
|
||||
|
||||
|
||||
/**
|
||||
* 声明队列绑定交换机
|
||||
*
|
||||
* @author muyu
|
||||
*/
|
||||
@Configuration
|
||||
public class TutConfig {
|
||||
|
||||
@Bean
|
||||
public Queue fault() {
|
||||
return new Queue(MQQueueConstants.ALARM_QUEUE,true);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Queue alarm() {
|
||||
return new Queue(MQQueueConstants.FAULT_QUEUE, true);
|
||||
}
|
||||
}
|
|
@ -3,12 +3,10 @@ package com.muyu.analyze.service.impl;
|
|||
import com.muyu.analyze.service.VehicleService;
|
||||
import com.muyu.analyze.utils.StateConstant;
|
||||
import com.muyu.business.domain.FaultLogs;
|
||||
import com.muyu.common.core.constant.MQQueueConstants;
|
||||
import com.muyu.common.core.utils.uuid.IdUtils;
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
import com.muyu.system.common.domain.VehicleData;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -29,8 +27,7 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
public class BreakdownImpl implements VehicleService{
|
||||
|
||||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
@ -217,7 +214,7 @@ public class BreakdownImpl implements VehicleService{
|
|||
faultLogsAddReq.setFaultLevel(1);
|
||||
}
|
||||
|
||||
//进入这里的都是有故障的,存入hashset 放入redis
|
||||
// 进入这里的都是有故障的,存入hashset 放入redis
|
||||
String key = "breakdown";
|
||||
HashSet<FaultLogs> hashSet = new HashSet<>();
|
||||
hashSet.add(faultLogsAddReq);
|
||||
|
@ -236,10 +233,10 @@ public class BreakdownImpl implements VehicleService{
|
|||
// },new CorrelationData(UUID.randomUUID().toString()));
|
||||
|
||||
|
||||
rabbitTemplate.convertAndSend(MQQueueConstants.FAULT_QUEUE, faultLogsAddReq, message -> {
|
||||
message.getMessageProperties().setMessageId(IdUtils.fastSimpleUUID());
|
||||
return message;
|
||||
});
|
||||
// rabbitTemplate.convertAndSend(MQQueueConstants.FAULT_QUEUE, faultLogsAddReq, message -> {
|
||||
// message.getMessageProperties().setMessageId(IdUtils.fastSimpleUUID());
|
||||
// return message;
|
||||
// });
|
||||
|
||||
log.info("车辆VIN:"+vehicleData.getVin()+"故障事件已记录");
|
||||
log.info("故障事件结束");
|
||||
|
|
|
@ -2,19 +2,13 @@ package com.muyu.analyze.service.impl;
|
|||
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.muyu.analyze.mapper.VehicleMapper;
|
||||
import com.muyu.analyze.service.VehicleService;
|
||||
import com.muyu.business.domain.FaultLogs;
|
||||
import com.muyu.business.domain.Fence;
|
||||
import com.muyu.common.core.constant.MQQueueConstants;
|
||||
import com.muyu.common.core.utils.DateUtils;
|
||||
import com.muyu.common.core.utils.uuid.IdUtils;
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
import com.muyu.system.common.domain.Car;
|
||||
import com.muyu.system.common.domain.VehicleData;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -44,8 +38,6 @@ public class FenceAlarmImpl implements VehicleService {
|
|||
@Autowired
|
||||
private VehicleMapper vehicleMapper;
|
||||
|
||||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
@Override
|
||||
public void eventResolution(VehicleData analyze) throws JsonProcessingException {
|
||||
|
@ -108,21 +100,21 @@ public class FenceAlarmImpl implements VehicleService {
|
|||
}
|
||||
|
||||
|
||||
FaultLogs faultLogs = new FaultLogs();
|
||||
faultLogs.setCarVin(vin);
|
||||
faultLogs.setFaultCode("WEILAN");
|
||||
faultLogs.setStartAlarmTime(DateUtils.getNowDate());
|
||||
faultLogs.setAlarmFlag("Y");
|
||||
faultLogs.setDisposeStatus("1");
|
||||
// FaultLogs faultLogs = new FaultLogs();
|
||||
// faultLogs.setCarVin(vin);
|
||||
// faultLogs.setFaultCode("WEILAN");
|
||||
// faultLogs.setStartAlarmTime(DateUtils.getNowDate());
|
||||
// faultLogs.setAlarmFlag("Y");
|
||||
// faultLogs.setDisposeStatus("1");
|
||||
|
||||
//对象变json
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
String faultLog = objectMapper.writeValueAsString(faultLogs);
|
||||
// ObjectMapper objectMapper = new ObjectMapper();
|
||||
// String faultLog = objectMapper.writeValueAsString(faultLogs);
|
||||
|
||||
rabbitTemplate.convertAndSend(MQQueueConstants.ALARM_QUEUE, faultLog , message -> {
|
||||
message.getMessageProperties().setMessageId(IdUtils.fastSimpleUUID());
|
||||
return message;
|
||||
});
|
||||
// rabbitTemplate.convertAndSend(MQQueueConstants.ALARM_QUEUE, faultLog , message -> {
|
||||
// message.getMessageProperties().setMessageId(IdUtils.fastSimpleUUID());
|
||||
// return message;
|
||||
// });
|
||||
|
||||
|
||||
|
||||
|
@ -130,76 +122,9 @@ public class FenceAlarmImpl implements VehicleService {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
System.out.println(carMarking);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
for (Map.Entry<String, Object> entry : fence1.entrySet()) {
|
||||
for (String s : split1) {
|
||||
String key = entry.getKey();
|
||||
if (s.equals(key)){
|
||||
String value = (String) entry.getValue();
|
||||
|
||||
String[] split = value.split(";");
|
||||
|
||||
boolean withinFence = isWithinFence(pointLat, pointLng, Arrays.asList(split));
|
||||
|
||||
if (withinFence){
|
||||
log.info("车辆vin:"+vin+"------在电子围栏"+key+"---正常行驶---");
|
||||
}else {
|
||||
log.info("车辆vin:"+vin+"------驶出电子围栏"+key+"---报警---");
|
||||
|
||||
String key1 = "fenceType1";
|
||||
|
||||
HashSet<Fence> hashSet = new HashSet<>();
|
||||
fence.setCarVin(vin);
|
||||
fence.setFenceType("驶出");
|
||||
fence.setFenceId(Integer.valueOf(key));
|
||||
|
||||
hashSet.add(fence);
|
||||
redisService.setCacheSet(key1,hashSet);
|
||||
redisService.expire(key1, 20, TimeUnit.MINUTES); // 设置过期时间
|
||||
}
|
||||
|
||||
|
||||
FaultLogs faultLogs = new FaultLogs();
|
||||
faultLogs.setCarVin(vin);
|
||||
faultLogs.setFaultCode("GTX007");
|
||||
faultLogs.setStartAlarmTime(DateUtils.getNowDate());
|
||||
faultLogs.setAlarmFlag("Y");
|
||||
faultLogs.setDisposeStatus("1");
|
||||
|
||||
|
||||
rabbitTemplate.convertAndSend(MQQueueConstants.ALARM_QUEUE, faultLogs , message -> {
|
||||
message.getMessageProperties().setMessageId(IdUtils.fastSimpleUUID());
|
||||
return message;
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
//false是除了围栏要报警
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,19 +1,14 @@
|
|||
package com.muyu.analyze.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import com.muyu.analyze.mapper.VehicleMapper;
|
||||
import com.muyu.analyze.service.VehicleService;
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
import com.muyu.system.common.domain.VehicleData;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ProjectName: cloud-vehicles
|
||||
|
@ -39,9 +34,9 @@ public class StoredEventImpl implements VehicleService {
|
|||
@Override
|
||||
public void eventResolution(VehicleData analyze) {
|
||||
|
||||
Integer cacheObject = redisService.getCacheObject("records:info:" + analyze.getVin());
|
||||
|
||||
Integer id = (Integer)redisService.getCacheObject("records:info:" + analyze.getVin());
|
||||
analyze.setRecordsId(id);
|
||||
analyze.setRecordsId(cacheObject);
|
||||
|
||||
|
||||
list.add(analyze);
|
||||
|
|
|
@ -1,96 +0,0 @@
|
|||
//package com.muyu.analyze.utils;
|
||||
//
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.apache.kafka.clients.consumer.ConsumerConfig;
|
||||
//import org.apache.kafka.clients.consumer.ConsumerRecords;
|
||||
//import org.apache.kafka.clients.consumer.KafkaConsumer;
|
||||
//import org.apache.kafka.clients.producer.KafkaProducer;
|
||||
//import org.apache.kafka.clients.producer.ProducerConfig;
|
||||
//import org.apache.kafka.clients.producer.ProducerRecord;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//import javax.annotation.PostConstruct;
|
||||
//import java.time.Duration;
|
||||
//import java.util.Collections;
|
||||
//import java.util.Properties;
|
||||
//
|
||||
///**
|
||||
// * @ProjectName: cloud-vehicles
|
||||
// * @PackageName: com.muyu.analyze.utils
|
||||
// * @Description TODO
|
||||
// * @Author HuangDaJu
|
||||
// * @Date 2024/4/8 12:41
|
||||
// * @Version 1.0
|
||||
// */
|
||||
//@Component
|
||||
//@Slf4j
|
||||
//public class Test {
|
||||
//
|
||||
// private static final String TOPIC_NAME = "online";
|
||||
// private static final String BOOTSTRAP_SERVERS = "10.10.26.4:9092";
|
||||
//
|
||||
// public static void main(String[] args) {
|
||||
// //生产者示例
|
||||
// produceMessage();
|
||||
//
|
||||
// //消费者示例
|
||||
// consumerMessages();
|
||||
//
|
||||
// }
|
||||
//
|
||||
// //生产者
|
||||
// @PostConstruct
|
||||
// private static void produceMessage() {
|
||||
// Properties props = new Properties();
|
||||
// props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, BOOTSTRAP_SERVERS);
|
||||
// props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer");
|
||||
// props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer");
|
||||
//
|
||||
// KafkaProducer<String, String> producer = new KafkaProducer<>(props);
|
||||
// //创建生产者
|
||||
// try {
|
||||
//
|
||||
// //发送消息
|
||||
// for (int i = 0; i < 10000; i++) {
|
||||
// String message = "佳佳来喽" + (i + 1);
|
||||
// producer.send(new ProducerRecord<>(TOPIC_NAME, message));
|
||||
//
|
||||
// System.out.println("发送消息:" + message);
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// } finally {
|
||||
// producer.close();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// //消费者
|
||||
// private static void consumerMessages() {
|
||||
// Properties props = new Properties();
|
||||
// props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, BOOTSTRAP_SERVERS);
|
||||
// props.put(ConsumerConfig.GROUP_ID_CONFIG, "my-consumer-group");
|
||||
// props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer");
|
||||
// props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer");
|
||||
//
|
||||
// //创建消费者
|
||||
// KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props);
|
||||
//
|
||||
// try {
|
||||
//
|
||||
// //订阅主题
|
||||
// consumer.subscribe(Collections.singletonList(TOPIC_NAME));
|
||||
//
|
||||
// //持续消费消息
|
||||
// while (true) {
|
||||
// ConsumerRecords<String, String> records = consumer.poll(Duration.ofMillis(100));
|
||||
// records.forEach(record -> {
|
||||
// System.out.println("消费者接受到的消息值:" + record.value());
|
||||
// });
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// } finally {
|
||||
// consumer.close();
|
||||
// }
|
||||
// }
|
||||
//}
|
|
@ -1,73 +0,0 @@
|
|||
package com.aliyun.sample;
|
||||
|
||||
import com.aliyuncs.DefaultAcsClient;
|
||||
import com.aliyuncs.IAcsClient;
|
||||
import com.aliyuncs.ecs.model.v20140526.CreateInstanceRequest;
|
||||
import com.aliyuncs.ecs.model.v20140526.CreateInstanceResponse;
|
||||
import com.aliyuncs.exceptions.ClientException;
|
||||
import com.aliyuncs.profile.DefaultProfile;
|
||||
|
||||
/**
|
||||
* 阿里云ECS实例创建器示例类。
|
||||
* 本类用于演示如何通过阿里云SDK在Java中创建一个ECS实例。
|
||||
*/
|
||||
public class AliyunEcsInstanceCreator {
|
||||
|
||||
/**
|
||||
* 主函数:创建一个阿里云ECS实例。
|
||||
*
|
||||
* @param args 命令行参数(未使用)
|
||||
*
|
||||
* 注意:本示例中使用的AccessKeyId、AccessKeySecret、regionId、imageId、instanceType等信息为示意,
|
||||
* 实际使用时需要替换为有效的阿里云账号信息。
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
// 设置阿里云账号的认证信息
|
||||
String accessKeyId = "LTAI5tANGefs2gi8nsu4AoSZ";
|
||||
String accessKeySecret = "Ut5RaJvvG7dP8hgK82qjdtvyUA6x8g";
|
||||
String regionId = "cn-zhangjiakou"; // 实例所在的地域ID
|
||||
String instanceName = "Test"; // 实例名称
|
||||
String imageId = "m-8vb1u2bhootky8sgg2ft"; // 镜像ID
|
||||
String instanceType = "ecs.t6-c2m1.large"; // 实例规格
|
||||
|
||||
// 初始化阿里云客户端
|
||||
DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
|
||||
IAcsClient client = new DefaultAcsClient(profile);
|
||||
|
||||
// 配置创建实例的请求参数
|
||||
CreateInstanceRequest request = new CreateInstanceRequest();
|
||||
request.setImageId(imageId); // 设置使用的镜像ID
|
||||
request.setInstanceName(instanceName); // 设置实例名称
|
||||
request.setInstanceType(instanceType); // 设置实例规格
|
||||
|
||||
// 配置抢占式实例的属性
|
||||
request.setInstanceChargeType("PostPaid"); // 实例付费类型,此处为按量付费
|
||||
request.setSpotStrategy("SpotWithPriceLimit"); // 抢占式实例的出价策略,设置为有限价格
|
||||
|
||||
|
||||
request.setImageId(imageId); // 设置使用的镜像ID
|
||||
request.setInstanceName(instanceName); // 设置实例名称
|
||||
request.setInstanceType(instanceType); // 设置实例规格
|
||||
|
||||
|
||||
// 配置网络和公网带宽
|
||||
request.setVSwitchId("vpc-8vbbw0obosvd5p5i2y5nq"); // 设置实例所在的子网ID
|
||||
request.setInternetMaxBandwidthOut(5); // 设置公网出带宽上限,单位为Mbps
|
||||
|
||||
|
||||
// 配置抢占式实例的属性
|
||||
request.setInstanceChargeType("PostPaid"); // 实例付费类型,此处为按量付费
|
||||
request.setSpotStrategy("SpotWithPriceLimit"); // 抢占式实例的出价策略,设置为有限价格
|
||||
|
||||
request.setSpotPriceLimit(1F); // 设置抢占式实例的最高每小时价格限制
|
||||
|
||||
|
||||
// 发送创建实例的请求并处理响应
|
||||
try {
|
||||
CreateInstanceResponse response = client.getAcsResponse(request);
|
||||
System.out.println("Instance Created: " + response.getInstanceId());
|
||||
} catch (ClientException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -85,11 +85,7 @@
|
|||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-file-remote</artifactId>
|
||||
</dependency>
|
||||
<!--MQ-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -5,26 +5,20 @@ import com.muyu.business.domain.req.AlarmLogsReq;
|
|||
import com.muyu.business.domain.req.AlarmLogsUpdReq;
|
||||
import com.muyu.business.domain.res.AlarmLogsResponse;
|
||||
import com.muyu.business.service.AlarmLogsService;
|
||||
import com.muyu.common.core.constant.MQQueueConstants;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.web.controller.BaseController;
|
||||
import com.muyu.common.core.web.page.TableDataInfo;
|
||||
import com.muyu.common.log.annotation.Log;
|
||||
import com.muyu.common.log.enums.BusinessType;
|
||||
import com.muyu.common.security.annotation.RequiresPermissions;
|
||||
import com.rabbitmq.client.Channel;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.rabbit.annotation.Queue;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -106,31 +100,31 @@ public class AlarmLogsController extends BaseController {
|
|||
|
||||
|
||||
|
||||
@RabbitListener(queuesToDeclare = {@Queue(value = MQQueueConstants.ALARM_QUEUE, declare = "true")})
|
||||
public void sendSms(String alarmLog, Message message, Channel channel) {
|
||||
log.info("消息队列:【{}】,收到报警日志:【{}】",MQQueueConstants.ALARM_QUEUE,alarmLog);
|
||||
try {
|
||||
String messageId = message.getMessageProperties().getMessageId();
|
||||
Long count = redisTemplate.opsForSet().add(MQQueueConstants.ALARM_QUEUE, messageId);
|
||||
if (count.intValue() > 0){
|
||||
alarmLogsService.alarmLogsService(alarmLog);
|
||||
// 消息确认
|
||||
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
|
||||
log.info("消息队列:【{}】,收到报警日志:【{}】,消费成功...",MQQueueConstants.ALARM_QUEUE,alarmLog);
|
||||
}else {
|
||||
log.error("消息队列:【{}】,收到报警日志:【{}】,消费重复...",MQQueueConstants.ALARM_QUEUE,alarmLog);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
log.error("消息队列:【{}】,收到报警日志:【{}】,消费异常:【{}】",MQQueueConstants.ALARM_QUEUE,alarmLog,e.getMessage());
|
||||
// 消息回退
|
||||
try {
|
||||
channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, true);
|
||||
} catch (IOException ex) {
|
||||
log.error("消息队列:【{}】,收到报警日志:【{}】,消息退回异常:【{}】",MQQueueConstants.ALARM_QUEUE,alarmLog,e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
// @RabbitListener(queuesToDeclare = {@Queue(value = MQQueueConstants.ALARM_QUEUE, declare = "true")})
|
||||
// public void sendSms(String alarmLog, Message message, Channel channel) {
|
||||
// log.info("消息队列:【{}】,收到报警日志:【{}】",MQQueueConstants.ALARM_QUEUE,alarmLog);
|
||||
// try {
|
||||
// String messageId = message.getMessageProperties().getMessageId();
|
||||
// Long count = redisTemplate.opsForSet().add(MQQueueConstants.ALARM_QUEUE, messageId);
|
||||
// if (count.intValue() > 0){
|
||||
// alarmLogsService.alarmLogsService(alarmLog);
|
||||
// // 消息确认
|
||||
// channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
|
||||
// log.info("消息队列:【{}】,收到报警日志:【{}】,消费成功...",MQQueueConstants.ALARM_QUEUE,alarmLog);
|
||||
// }else {
|
||||
// log.error("消息队列:【{}】,收到报警日志:【{}】,消费重复...",MQQueueConstants.ALARM_QUEUE,alarmLog);
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// log.error("消息队列:【{}】,收到报警日志:【{}】,消费异常:【{}】",MQQueueConstants.ALARM_QUEUE,alarmLog,e.getMessage());
|
||||
// // 消息回退
|
||||
// try {
|
||||
// channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, true);
|
||||
// } catch (IOException ex) {
|
||||
// log.error("消息队列:【{}】,收到报警日志:【{}】,消息退回异常:【{}】",MQQueueConstants.ALARM_QUEUE,alarmLog,e.getMessage());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -7,28 +7,22 @@ import com.muyu.business.domain.req.FaultLogsUpdReq;
|
|||
import com.muyu.business.domain.res.FaultLogsResponse;
|
||||
import com.muyu.business.service.AlarmLogsService;
|
||||
import com.muyu.business.service.FaultLogsService;
|
||||
import com.muyu.common.core.constant.MQQueueConstants;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.web.controller.BaseController;
|
||||
import com.muyu.common.core.web.page.TableDataInfo;
|
||||
import com.muyu.common.log.annotation.Log;
|
||||
import com.muyu.common.log.enums.BusinessType;
|
||||
import com.muyu.common.security.annotation.RequiresPermissions;
|
||||
import com.rabbitmq.client.Channel;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.rabbit.annotation.Queue;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -115,29 +109,28 @@ public class FaultLogsController extends BaseController {
|
|||
return toAjax(faultLogsService.deleteFaultLogsByIds(logIds));
|
||||
}
|
||||
|
||||
@RabbitListener(queuesToDeclare = {@Queue(value = MQQueueConstants.FAULT_QUEUE, declare = "true")})
|
||||
public void sendSms(FaultLogs faultLogs, Message message, Channel channel) {
|
||||
log.info("消息队列:【{}】,收到故障日志:【{}】",MQQueueConstants.FAULT_QUEUE,faultLogs);
|
||||
try {
|
||||
String messageId = message.getMessageProperties().getMessageId();
|
||||
Long count = redisTemplate.opsForSet().add(MQQueueConstants.FAULT_QUEUE, messageId);
|
||||
if (count.intValue() > 0){
|
||||
faultLogsService.insertFaultLogs(faultLogs);
|
||||
// 消息确认
|
||||
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
|
||||
log.info("消息队列:【{}】,收到故障日志:【{}】,消费成功...",MQQueueConstants.FAULT_QUEUE,faultLogs);
|
||||
}else {
|
||||
log.error("消息队列:【{}】,收到故障日志:【{}】,消费重复...",MQQueueConstants.FAULT_QUEUE,faultLogs);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
log.error("消息队列:【{}】,收到故障日志:【{}】,消费异常:【{}】",MQQueueConstants.FAULT_QUEUE,faultLogs,e.getMessage());
|
||||
// 消息回退
|
||||
try {
|
||||
channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, true);
|
||||
} catch (IOException ex) {
|
||||
log.error("消息队列:【{}】,收到故障日志:【{}】,消息退回异常:【{}】",MQQueueConstants.FAULT_QUEUE,faultLogs,e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
// @RabbitListener(queuesToDeclare = {@Queue(value = MQQueueConstants.FAULT_QUEUE, declare = "true")})
|
||||
// public void sendSms(FaultLogs faultLogs, Message message, Channel channel) {
|
||||
// log.info("消息队列:【{}】,收到故障日志:【{}】",MQQueueConstants.FAULT_QUEUE,faultLogs);
|
||||
// try {
|
||||
// String messageId = message.getMessageProperties().getMessageId();
|
||||
// Long count = redisTemplate.opsForSet().add(MQQueueConstants.FAULT_QUEUE, messageId);
|
||||
// if (count.intValue() > 0){
|
||||
// faultLogsService.insertFaultLogs(faultLogs);
|
||||
// // 消息确认
|
||||
// channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
|
||||
// log.info("消息队列:【{}】,收到故障日志:【{}】,消费成功...",MQQueueConstants.FAULT_QUEUE,faultLogs);
|
||||
// }else {
|
||||
// log.error("消息队列:【{}】,收到故障日志:【{}】,消费重复...",MQQueueConstants.FAULT_QUEUE,faultLogs);
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// log.error("消息队列:【{}】,收到故障日志:【{}】,消费异常:【{}】",MQQueueConstants.FAULT_QUEUE,faultLogs,e.getMessage());
|
||||
// // 消息回退
|
||||
// try {
|
||||
// channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, true);
|
||||
// } catch (IOException ex) {
|
||||
// log.error("消息队列:【{}】,收到故障日志:【{}】,消息退回异常:【{}】",MQQueueConstants.FAULT_QUEUE,faultLogs,e.getMessage());
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import com.muyu.business.service.FaultLogsService;
|
|||
import com.muyu.common.core.utils.StringUtils;
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -52,8 +52,7 @@ public class AlarmLogsServiceImpl extends ServiceImpl<AlarmLogsMapper, AlarmLogs
|
|||
/**
|
||||
* 注入rabbitmq
|
||||
*/
|
||||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
|
||||
@Override
|
||||
public List<AlarmLogsResponse> selectAlarmLogsList(AlarmLogsReq alarmLogsReq) {
|
||||
|
|
|
@ -35,6 +35,7 @@ public class RecordsServiceImpl extends ServiceImpl<RecordsMapper,Records>
|
|||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
|
||||
/**
|
||||
* @author YinYuYang
|
||||
* @date 2024/4/5 11:10
|
||||
|
@ -91,7 +92,11 @@ public class RecordsServiceImpl extends ServiceImpl<RecordsMapper,Records>
|
|||
recordsMapper.insert(records);
|
||||
|
||||
Integer recordsId = records.getRecordsId();
|
||||
redisService.setCacheSet("records:info:"+vin,recordsId);
|
||||
|
||||
/*
|
||||
*上线缓存id,为历史轨迹做准备
|
||||
*/
|
||||
redisService.setCacheObject("records:info:"+vin,recordsId);
|
||||
|
||||
return recordsId;
|
||||
}
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
//package com.muyu.business.sms;
|
||||
//
|
||||
//import com.muyu.business.service.AlarmLogsService;
|
||||
//import com.muyu.business.service.FaultLogsService;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//@Slf4j
|
||||
//@Component
|
||||
//public class SendSmsConfig {
|
||||
//
|
||||
// /**
|
||||
// * 注入redis工具类
|
||||
// */
|
||||
// @Autowired
|
||||
// private StringRedisTemplate redisTemplate;
|
||||
//
|
||||
// /**
|
||||
// * 注入报警日志服务
|
||||
// */
|
||||
// @Autowired
|
||||
// private AlarmLogsService alarmLogsService;
|
||||
//
|
||||
// /**
|
||||
// * 注入故障日志服务
|
||||
// */
|
||||
// @Autowired
|
||||
// private FaultLogsService faultLogsService;
|
||||
//
|
||||
//
|
||||
//
|
||||
//}
|
Loading…
Reference in New Issue