feat():before testRunner

master
Saisai Liu 2024-06-18 18:21:54 +08:00
parent a412e584db
commit 40ab1e3859
5 changed files with 37 additions and 24 deletions

View File

@ -18,17 +18,17 @@ import java.util.List;
*/
@RestController
@Log4j2
@RequestMapping("fluxmq/")
@RequestMapping("/fluxmq")
public class FluxGetInfoController {
@Autowired
private FluxGetInfoService fluxGetInfoService;
@GetMapping("/getInfo/")
@GetMapping("/getInfo")
public Result getInfo(){
return fluxGetInfoService.getInfo(null);
}
@GetMapping("getIps/")
@GetMapping("/getIps")
public Result<List<MqttServerModel>> getIps(){
return fluxGetInfoService.getIps();
}

View File

@ -38,10 +38,14 @@ public class SelectInstances {
// 工程代码泄露可能会导致 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("LTAI5t7vsLXtqTJKve7JipnX")
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
.setAccessKeySecret("AIyMaSTKQtsB1V5sVqlNAGbQzxgXnS");
//自己的
// // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
// .setAccessKeyId("LTAI5t7vsLXtqTJKve7JipnX")
// // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
// .setAccessKeySecret("AIyMaSTKQtsB1V5sVqlNAGbQzxgXnS");
// 杜云飞
.setAccessKeyId("LTAI5tPTk3MFkmCGBbnQgmrM")
.setAccessKeySecret("q7rLjxrI0SLBXlvNT4VmYcHCNCY2p6");
// Endpoint 请参考 https://api.aliyun.com/product/Ecs
config.endpoint = "ecs.cn-zhangjiakou.aliyuncs.com";
return new com.aliyun.ecs20140526.Client(config);
@ -84,7 +88,7 @@ public class SelectInstances {
}
//1分钟
@Scheduled(cron = "* 0/5 * * * ? ")
@Scheduled(cron = "0 0/5 * * * ? ")
//10秒
// @Scheduled(cron = "0/10 * * * * ? ")
public void saveIps() {

View File

@ -6,6 +6,7 @@ import com.mobai.domain.*;
import com.mobai.domain.flux.ApifoxModel;
import com.mobai.openApi.SelectInstances;
import com.mobai.service.FluxGetInfoService;
import lombok.Synchronized;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
@ -19,6 +20,7 @@ import org.springframework.web.client.RestTemplate;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.Lock;
import java.util.stream.Collectors;
/**
@ -80,29 +82,34 @@ public class FluxGetInfoServiceImpl implements FluxGetInfoService {
// "timestamp": "11111" new Date().getMillis()
// "username": "你好" Vin + timestamp
// "nonce": "33" 随机
log.warn("参数为:{}", req);
// String string = redis.opsForList().range("fluxMq", 0, -1).get(0);
// List<MqttServerModel> mqtts = JSON.parseArray(string, MqttServerModel.class);
// log.info("集合:{}",mqtts);
// tcp://192.168.1.1:1883
if (redis.hasKey("fluxMqIndex")) {
redis.opsForValue().increment("fluxMqIndex", 1);
} else {
redis.opsForValue().set("fluxMqIndex", 0 + "");
}
int index = Integer.valueOf(redis.opsForValue().get("fluxMqIndex"));
log.info("下标:{}", index);
synchronized(this){
if (redis.hasKey("fluxMqIndex")) {
redis.opsForValue().increment("fluxMqIndex", 1);
} else {
redis.opsForValue().set("fluxMqIndex", 0 + "");
}
int index = Integer.valueOf(redis.opsForValue().get("fluxMqIndex"));
log.info("下标:{}", index);
// List<String> fluxmq = redis.opsForList().range("mqttIp", 0, 5);
String mqttIp = redis.opsForList().index("mqttIp", index);
String mqttIp = redis.opsForList().index("mqttIp", index);
// log.info(fluxmq);
log.info(mqttIp);
MqttServerModel mqttServerModel = JSON.parseObject(mqttIp, MqttServerModel.class);
if (index + 1 == 100) {
redis.opsForValue().set("fluxMqIndex", 0 + "");
log.info(mqttIp);
MqttServerModel mqttServerModel = JSON.parseObject(mqttIp, MqttServerModel.class);
if (index + 1 >= 80) {
redis.opsForValue().set("fluxMqIndex", 0 + "");
}
log.info("已获取到对象:{}", mqttServerModel);
return Result.success(mqttServerModel);
}
log.info("已获取到对象:{}", mqttServerModel);
return Result.success(mqttServerModel);
}
@Override

View File

@ -1,6 +1,7 @@
package com.mobai.util;
import com.alibaba.fastjson2.JSON;
import lombok.extern.log4j.Log4j2;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
@ -16,6 +17,7 @@ import java.util.concurrent.TimeUnit;
* @author muyu
**/
@SuppressWarnings(value = {"unchecked", "rawtypes"})
@Log4j2
@Component
@Lazy
public class RedisService {
@ -270,7 +272,7 @@ public class RedisService {
public void increment(String s,int i) {
if (Boolean.TRUE.equals(stringRedisTemplate.hasKey(s))){
String o = stringRedisTemplate.opsForValue().get(s);
System.out.println(o);
log.info("当前游标::"+o);
stringRedisTemplate.opsForValue().increment(s,i);
}else {
stringRedisTemplate.opsForValue().set(s,i+"");

View File

@ -2,7 +2,7 @@ server:
port: 8081
spring:
redis:
host: 175.24.138.82
host: 127.0.0.1
port: 6379
password:
rabbitmq: