解决网关不定时出现Refresh routes error !!!

最近跟踪服务器日志,经常发现如下异常

ERROR o.s.c.g.r.CachingRouteLocator - [handleRefreshError,94] - Refresh routes error !!!
org.springframework.expression.spel.SpelEvaluationException: EL1005E: Type cannot be found 'org.springframework.util.StreamUtils'

网关隔一段时间就会报动态刷新路的异常信息,导致线上出现请求网关超时,重启之后网关正常

在Nacos 管理端下线服务后,Nacos服务端有定时延迟机制导致不能及时更新状态,导致服务重启后gateway网关依然会把请求分配到已经下线且停机的服务,导致接口提示未找到服务

针对此种情况做出下面解决方案,

@Component
@Slf4j
public  class NacosInstancesChangeEventListener extends Subscriber {

    @Override
    public void onEvent(InstancesChangeEvent event) {
        log.info("spring gateway receive refresh event :{}, refresh cache start ...", JacksonUtils.toJson(event));
        LoadBalancerCacheManager cacheManager = SpringUtils.getBean(LoadBalancerCacheManager.class);
        Cache cache = cacheManager.getCache(CachingServiceInstanceListSupplier.SERVICE_INSTANCE_CACHE_NAME);
        if (cache != null) {
            cache.evict(event.getServiceName());
        }
        log.info("spring gateway refresh finish .");
    }

    @Override
    public Class subscribeType() {
        return InstancesChangeEvent.class;
    }
}

你可能感兴趣的:(前端,nacos)