4.20-2
parent
85c99c55bd
commit
377705887b
|
@ -91,10 +91,12 @@ public class GatewayZSetNodeCache extends GatewayCacheAbs<String> {
|
|||
}
|
||||
|
||||
|
||||
public Map<Object, Double> get2(String ip) {
|
||||
return redisService.getCacheZSetScore(encode(gatewayZSetCount) + ip);
|
||||
public void increment(String ip,Double score) {
|
||||
redisService.incrementScore(encode(gatewayZSetCount) , ip,score);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -206,6 +206,11 @@ public class RedisService
|
|||
return memberScores;
|
||||
}
|
||||
|
||||
public <T> Double incrementScore(final String key,final T value,final Double score) {
|
||||
return redisTemplate.opsForZSet().incrementScore(key,value,score);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -118,6 +118,7 @@ public class Consumer {
|
|||
|
||||
|
||||
Thread.sleep(5000);
|
||||
|
||||
//刷新负载均衡
|
||||
gatewayLoadService.refreshLoad();
|
||||
|
||||
|
|
|
@ -264,8 +264,7 @@ public class GatewayLoadServiceImpl implements GatewayLoadService {
|
|||
int connectSize = mqttInfo.getIntValue("connectSize");
|
||||
|
||||
log.info("服务器:"+ip+"-车辆连接数:"+connectSize);
|
||||
// 更新Redis中服务器的连接数ZSet数据类型
|
||||
gatewayZSetNodeCache.put(ip,connectSize);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.muyu.center.service.impl;
|
|||
|
||||
import com.muyu.center.common.domain.WorkGatewayNode;
|
||||
import com.muyu.center.common.gateway.cache.GatewayVehicleNode;
|
||||
import com.muyu.center.service.GatewayLoadService;
|
||||
import com.muyu.center.service.GatewayVehicleService;
|
||||
import com.muyu.center.common.domain.Result;
|
||||
import com.muyu.center.common.gateway.cache.GatewayNodeSetVinCache;
|
||||
|
@ -40,6 +41,9 @@ public class GatewayVehicleServiceImpl implements GatewayVehicleService {
|
|||
|
||||
private final GatewayVehicleNode gatewayVehicleNode;
|
||||
|
||||
|
||||
private final GatewayLoadService gatewayLoadService;
|
||||
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
|
@ -53,37 +57,15 @@ public class GatewayVehicleServiceImpl implements GatewayVehicleService {
|
|||
@Override
|
||||
public Result<String> topLine(String vin) {
|
||||
|
||||
String url="http://127.0.0.1:9010/gateway/load/node";
|
||||
String ip = gatewayLoadService.loadNode();
|
||||
|
||||
Result data = restTemplate.getForObject(url, Result.class);
|
||||
gatewayVehicleNode.put(vin,ip);
|
||||
|
||||
gatewayVehicleNode.put(vin,data.getData().toString());
|
||||
gatewayNodeSetVinCache.put(ip,vin);
|
||||
|
||||
gatewayNodeSetVinCache.put(data.getData().toString(),vin);
|
||||
gatewayZSetNodeCache.increment(ip,1.0);
|
||||
|
||||
//// Map<Object, Double> map = gatewayZSetNodeCache.get2(data.getData().toString());
|
||||
// Set<String> zSet = gatewayZSetNodeCache.redisService.getCacheZSet("gateway:zSet:count" + data.getData());
|
||||
// Map<Object, Double> map = gatewayZSetNodeCache.redisService.getCacheZSetScore("gateway:zSet:count" + data.getData());
|
||||
|
||||
|
||||
|
||||
// Map<Object, Double> map = new HashMap<>();
|
||||
// ZSetOperations<String, Object> zSetOperations =gatewayZSetNodeCache.redisService. redisTemplate.opsForZSet();
|
||||
// // 构建一个 Map 用于存储成员和分数的对应关系
|
||||
// zSetOperations.rangeWithScores("gateway:zSet:count" + data.getData(), 0, -1).forEach(tuple -> {
|
||||
// map.put(tuple.getValue(), tuple.getScore());
|
||||
// });
|
||||
//
|
||||
// System.out.println("------------------------------------------");
|
||||
// Double aDouble = map.get(data.getData());
|
||||
// System.out.println(map);
|
||||
// System.out.println(aDouble);
|
||||
// System.out.println("------------------------------------------");
|
||||
//
|
||||
//
|
||||
// gatewayZSetNodeCache.put(data.getData().toString(),1);
|
||||
|
||||
return Result.success(data.getData().toString());
|
||||
return Result.success(ip);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue