RouteLocatorBuilder does not use route order property
First, I'm not sure if this is a bug, or a lack of documentation, but when you use the RouteLocatorBuilder, the routes are never sorted, so using the route.order() method has no affect. I'm actually ok with this behavior, but if it is unintended I will future proof our configuration to add the order, even if it is not used at the moment.
The relevant bit in RouteLocatorBuilder:
public RouteLocator build() {
return () -> {
return Flux.fromIterable(this.routes).map((routeBuilder) -> {
return (Route)routeBuilder.build();
});
};
}
You are right, it seems a bug.
They are sorted later https://github.com/spring-cloud/spring-cloud-gateway/blob/67b612d4af1ad9882a95cd7db0025ef0c7633089/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/route/CachingRouteLocator.java#L62-L68
@spencergibb , it is expected that someone doing code based config manually instantiate the CachingRouteLocator? Here's my bean definition
@Bean
fun routes(routeLocatorBuilder: RouteLocatorBuilder, config: RouteConfig): RouteLocator {
val routes = routeLocatorBuilder.routes()
config.userContexts.forEach { routes.addPathFor(it) }
config.serviceRoutes.forEach { routes.addPathFor(it) }
config.thirdPartyServers.forEach { thirdParty ->
routes.addMissingSlashPath(thirdParty.path)
routes.route { predicate ->
predicate.path("${thirdParty.path}/**")
.uri(thirdParty.service)
}
}
return routes.build()
}
Which, by itself, never touches the CachingRouteLocator, and from what I can see nothing automatically wraps it in one either. It looks like it's easy enough to just new up the caching version with results from build(), but the difference in behavior between the two is never called anywhere, that I'm aware of.
No, it is instantiated here https://github.com/spring-cloud/spring-cloud-gateway/blob/43eb8ceb3925149eb376a91cbb0146899c0f2577/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java#L257-L263
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.