使用nacos做服务注册发现,当后端服务列表变化时,gateway缓存的服务列表没有更新
后端服务重启后,gateway没有及时获取最新的服务列表导致服务不可用
可以尝试使用Subscriber<InstancesChangeEvent>来实时监听Nacos实例变化 , 并通过清空LoadBalancerCacheManager缓存来保证Spring Cloud Gateway 的实例列表为最新实例.
Spring Cloud Gateway 服务实例列表缓存默认存活时间35s (spring.cloud.loadbalancer.cache.ttl: 35s)
后端服务重启后,gateway没有及时获取最新的服务列表导致服务不可用
SCG服务发现过程有缓存存在,会可能出现调用刚下线服务实例情况。
后端服务重启后,gateway没有及时获取最新的服务列表导致服务不可用
SCG服务发现过程有缓存存在,会可能出现调用刚下线服务实例情况。
通过上面提到的基于Subscriber<InstancesChangeEvent>监听nacos实例变化 , 有变化则清空对应服务的缓存可以解决这个问题
LoadBalancerCacheManager源码没有这个类?请问该如何清除缓存?
LoadBalancerCacheManager源码没有这个类?请问该如何清除缓存?
如果你用了其他的负载均衡器 , 则清空对应的缓存即可 , 不一定非得使用LoadBalancerCacheManager
org.springframework.cloud.loadbalancer.cache.LoadBalancerCacheManager 是以下依赖包中的类:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
我是用主动剔除解决的 https://juejin.cn/post/7249286832168566840
并加了如下配置
spring
cloud:
nacos:
discovery:
watch-delay: 10000
This issue has been open 30 days with no activity. This will be closed in 7 days.
This issue has been automatically marked as stale because it hasn't had any recent activity.If you think this should still be open, or the problem still persists, just pop a reply in the comments and one of the maintainers will (try!) to follow up. Thank you for your interest and contribution to the Sping Cloud Alibaba Community.