My Gateway is connected to Eureka Service Discovery. Every time a gateway client refresh its state in Eureka, all the routes in gateway are rebuilt. This is critical for me since I have redefined Route Locator and am downloading my routes from another service. How can I disable this behavior or change it?
The whole problem is org.springframework.cloud.gateway.route.RouteRefreshListener. When eureka client creates a HeartbeatEvent, it triggers the rebuilding of routes, is there any way to override this Bean? It does not implement the interface((
@Bean
@ConditionalOnClass(
name = "org.springframework.cloud.client.discovery.event.HeartbeatMonitor")
public RouteRefreshListener routeRefreshListener(
ApplicationEventPublisher publisher) {
return new RouteRefreshListener(publisher);
}
public class RouteRefreshListener implements ApplicationListener<ApplicationEvent> {
private final ApplicationEventPublisher publisher;
private HeartbeatMonitor monitor = new HeartbeatMonitor();
public RouteRefreshListener(ApplicationEventPublisher publisher) {
Assert.notNull(publisher, "publisher may not be null");
this.publisher = publisher;
}
@Override
public void onApplicationEvent(ApplicationEvent event) {
if (event instanceof ContextRefreshedEvent) {
ContextRefreshedEvent refreshedEvent = (ContextRefreshedEvent) event;
if (!WebServerApplicationContext.hasServerNamespace(
refreshedEvent.getApplicationContext(), "management")) {
reset();
}
}
else if (event instanceof RefreshScopeRefreshedEvent
|| event instanceof InstanceRegisteredEvent) {
reset();
}
else if (event instanceof ParentHeartbeatEvent) {
ParentHeartbeatEvent e = (ParentHeartbeatEvent) event;
resetIfNeeded(e.getValue());
}
else if (event instanceof HeartbeatEvent) {
HeartbeatEvent e = (HeartbeatEvent) event;
resetIfNeeded(e.getValue());
}
}
private void resetIfNeeded(Object value) {
if (this.monitor.update(value)) {
reset();
}
}
private void reset() {
this.publisher.publishEvent(new RefreshRoutesEvent(this));
}```
My Gateway is connected to Eureka Service Discovery. Every time a gateway client refresh its state in Eureka, all the routes in gateway are rebuilt. This is critical for me since I have redefined Route Locator and am downloading my routes from another service. How can I disable this behavior or change it?
The whole problem is org.springframework.cloud.gateway.route.RouteRefreshListener. When eureka client creates a HeartbeatEvent, it triggers the rebuilding of routes, is there any way to override this Bean? It does not implement the interface((