spring-cloud-gateway icon indicating copy to clipboard operation
spring-cloud-gateway copied to clipboard

Why RouteRefreshListener is added automatically?

Open zydzjy opened this issue 2 years ago • 2 comments

When i add "spring-cloud-starter-netflix-eureka-client",then SCG add RouteRefreshListener,which refresh routes definition automatically by publishing heartbeat event,is that problem,caus i don't want to refersh routes definition every heartbeat!

zydzjy avatar Jul 09 '22 17:07 zydzjy

i think, because spring.cluod.gateway.predicate.cloud-foundry-route-service.enable is true new service will join, old service may left.

MI-cool avatar Jul 12 '22 12:07 MI-cool

In GatewayDiscoveryClientAutoConfiguration class:

@Bean
@ConditionalOnClass(name = "org.springframework.cloud.client.discovery.event.HeartbeatMonitor")
public RouteRefreshListener routeRefreshListener(ApplicationEventPublisher publisher) {
	return new RouteRefreshListener(publisher);
}

I can not understand what is the relationship between HearbeatMonitor and RouteRereshListener!

zydzjy avatar Jul 13 '22 04:07 zydzjy

See https://github.com/spring-cloud/spring-cloud-gateway/blob/71014d10bfa040a08d3479b161b79b3c8cd0d4a8/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/route/RouteRefreshListener.java#L56-L63

We do this so routes located from discovery can be refreshed. Perhaps it should only be active if spring.cloud.gateway.discovery.locator.enabled=true

spencergibb avatar Jan 19 '23 19:01 spencergibb