网关进行优化,增加日志
This commit is contained in:
@ -41,6 +41,8 @@ public class DynamicRouteConfig implements RouteDefinitionLocator {
|
||||
// 最小刷新间隔(毫秒)
|
||||
private static final long MIN_REFRESH_INTERVAL = 3000;
|
||||
|
||||
private static final URI DEFAULT_URI = URI.create("http://localhost");
|
||||
|
||||
@Override
|
||||
public Flux<RouteDefinition> getRouteDefinitions() {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
@ -99,7 +101,9 @@ public class DynamicRouteConfig implements RouteDefinitionLocator {
|
||||
@EventListener
|
||||
public void onRefreshRoutes(RefreshRoutesEvent event) {
|
||||
long count = refreshCount.get();
|
||||
log.info("接收到路由刷新事件,当前为第{}次刷新", count);
|
||||
log.info("接收到路由刷新事件,当前为第{}次刷新, JVM内存使用: {}/{}", count,
|
||||
Runtime.getRuntime().freeMemory(),
|
||||
Runtime.getRuntime().totalMemory());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -118,7 +122,7 @@ public class DynamicRouteConfig implements RouteDefinitionLocator {
|
||||
List<ServiceInstance> instances = discoveryClient.getInstances(serviceName);
|
||||
if (instances == null || instances.isEmpty()) {
|
||||
log.warn("No available instances for service: {}, returning default URI", serviceName);
|
||||
return URI.create("http://localhost");
|
||||
return DEFAULT_URI;
|
||||
}
|
||||
int idx = index.getAndIncrement() & Integer.MAX_VALUE;
|
||||
ServiceInstance selected = instances.get(idx % instances.size());
|
||||
|
||||
Reference in New Issue
Block a user