Merge branch 'dev.gateway.aliyun' into dev

dev.event.processing
ywt 2024-10-09 21:47:56 +08:00
commit 1eb9952dc0
3 changed files with 19 additions and 10 deletions

View File

@ -46,6 +46,7 @@ public class AliYunEcsService {
public List<String> generateInstance(Integer amount) {
redisService.deleteObject("instanceIds");
redisService.deleteObject("instanceList");
redisService.deleteObject("count");
// 检查生成实例的数量是否有效
if (amount == null || amount <= 0) {
throw new ServiceException("生成数量不能小于1");
@ -120,6 +121,7 @@ public class AliYunEcsService {
// 创建运行时选项对象,用于配置请求的额外参数
RuntimeOptions runtimeOptions = new RuntimeOptions();
List<AliInstance> aliInstances = new ArrayList<>();
List<String> stringArrayList = new ArrayList<>();
try {
// 发送请求并获取响应对象
DescribeInstancesResponse describeInstancesResponse = client.describeInstancesWithOptions(request, runtimeOptions);
@ -135,12 +137,15 @@ public class AliYunEcsService {
// ip地址
String ipAddress = bodyInstance.getPublicIpAddress().getIpAddress().get(0);
log.info("实例ip为{}", ipAddress);
stringArrayList.add(ipAddress);
// 实例状态
String status = bodyInstance.getStatus();
log.info("实例状态为:{}", status);
AliInstance aliInstance = new AliInstance(instanceId, ipAddress, status);
aliInstances.add(aliInstance);
}
log.info("======================ipList{}",stringArrayList);
redisService.setCacheList("ipList",stringArrayList);
log.info("查询成功");
} catch (Exception e) {
log.error("查询服务器实例错误:[{}]", e.getMessage(), e);

View File

@ -35,7 +35,7 @@ public class VehicleConnectionController {
@PostMapping("/receiveMsg/connect")
public Result<MqttServerModel> receiveMsg(@RequestBody VehicleConnectionReq vehicleConnectionReq){
log.info(">"+vehicleConnectionReq);
return vehicleConnectionService.getConnect(vehicleConnectionReq);
vehicleConnectionService.getConnect(vehicleConnectionReq);
return Result.success();
}
}

View File

@ -7,6 +7,7 @@ import com.muyu.cloud.vehicle.gateway.domain.req.VehicleConnectionReq;
import com.muyu.cloud.vehicle.gateway.mapper.VehicleConnectionMapper;
import com.muyu.cloud.vehicle.gateway.service.VehicleConnectionService;
import com.muyu.common.core.domain.Result;
import com.muyu.common.redis.service.RedisService;
import lombok.extern.log4j.Log4j2;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
@ -26,6 +27,8 @@ public class VehicleConnectionServiceImpl implements VehicleConnectionService {
@Autowired
private StringRedisTemplate redisTemplate;
@Autowired
private RedisService redisService;
/**
*
@ -68,22 +71,23 @@ public class VehicleConnectionServiceImpl implements VehicleConnectionService {
redisTemplate.opsForValue().set("count",String.valueOf(count+1));
}
//根据游标count获取服务IP
String ip = redisTemplate.opsForList().index("ipList", count);
Object ipList = redisService.redisTemplate.opsForList().index("ipList", count);
//关联车辆和服务
this.addIpAddress(new VinIp(vehicleConnectionReq.getVehicleVin(),ip));
this.addIpAddress(new VinIp(vehicleConnectionReq.getVehicleVin(),ipList.toString()));
//响应信息
log.info("车辆:{}",vehicleConnectionReq.getVehicleVin()+"绑定成功:{}",ip);
return Result.success(new MqttServerModel("tcp://"+ip+":1883","vehicle"));
log.info("车辆:{}",vehicleConnectionReq.getVehicleVin()+"绑定成功:{}",ipList);
return Result.success(new MqttServerModel("tcp://"+ipList+":1883","vehicle"));
}else {
redisTemplate.opsForValue().set("count",String.valueOf(0));
//根据游标count获取服务器Ip
String ip = redisTemplate.opsForList().index("ipList", 0);
// String ip = redisTemplate.opsForList().index("ipList", 0);
Object ipList = redisService.redisTemplate.opsForList().index("ipList", 0);
//关联车辆和服务
this.addIpAddress(new VinIp(vehicleConnectionReq.getVehicleVin(),ip));
this.addIpAddress(new VinIp(vehicleConnectionReq.getVehicleVin(),ipList.toString()));
//响应信息
log.info("车辆:{}",vehicleConnectionReq.getVehicleVin(),"与:{}绑定成功",ip);
return Result.success(new MqttServerModel("tcp://"+ip+":1883","vehicle"));
log.info("车辆:{}",vehicleConnectionReq.getVehicleVin(),"与:{}绑定成功",ipList);
return Result.success(new MqttServerModel("tcp://"+ipList+":1883","vehicle"));
}
}
/**