Multiple loadings of route configurations when use Gateway together with Nacos-Discovery
Describe the bug spring-boot:2.6.4 spring-cloud-starter-gateway:3.1.4 spring-cloud-starter-alibaba-nacos-discovery:2021.0.1.0 1. When I use Gateway and Nacos as the service registry center, I set the log level to DEBUG. I noticed that the routing information is printed twice during service startup. After analyzing the source code, I found that the first loading occurs during the initialization of the web container, where the NacosAutoServiceRegistration class publishes the InstanceRegisteredEvent. The second loading happens after the service has fully started, when the ContextRefreshedEvent is published, which also triggers the loading of the routing definitions.
Another issue is that when used together with Nacos-Discovery, the NacosWatch in Nacos-Discovery will start a scheduled task that executes every 30 milliseconds by default. This task publishes a HeartbeatEvent.
NacosWatch:
this.watchFuture = this.taskScheduler.scheduleWithFixedDelay( this::nacosServicesWatch, this.properties.getWatchDelay());
The key point is that the data carried by the event is a long-type value that increases each time. This leads to this.monitor.update(value) is always true. As a result, the reset method is executed periodically.
I noticed that NacosWatch can be disabled using the spring.cloud.nacos.discovery.watch.enabled property, but I'm not sure whether it will affect the update of registered services.
Overall, these phenomena currently do not seem to have any impact on the functionality of the program. Indeed, there might be room for optimization here.