spring-cloud / spring-cloud-gateway

An API Gateway built on Spring Framework and Spring Boot providing routing and more.
http://cloud.spring.io
Apache License 2.0
4.55k stars 3.33k forks source link

Why RouteRefreshListener is added automatically? #2666

Open zydzjy opened 2 years ago

zydzjy commented 2 years ago

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!

MI-cool commented 2 years ago

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

zydzjy commented 2 years ago

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!

spencergibb commented 1 year ago

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