Skip to content

Commit 3f8e1e9

Browse files
committed
fix update scoped routes order problem
1 parent 4b8c93d commit 3f8e1e9

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

spring-cloud-gateway-server-webflux/src/main/java/org/springframework/cloud/gateway/route/CachingRouteLocator.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.cloud.gateway.route;
1818

19+
import java.util.Comparator;
1920
import java.util.List;
2021
import java.util.Map;
2122
import java.util.concurrent.ConcurrentHashMap;
@@ -27,6 +28,7 @@
2728
import reactor.core.publisher.Flux;
2829
import reactor.core.publisher.Mono;
2930
import reactor.core.publisher.Signal;
31+
import reactor.util.function.Tuple2;
3032

3133
import org.springframework.cloud.gateway.event.RefreshRoutesEvent;
3234
import org.springframework.cloud.gateway.event.RefreshRoutesResultEvent;
@@ -88,9 +90,14 @@ public void onApplicationEvent(RefreshRoutesEvent event) {
8890
final Mono<List<Route>> scopedRoutes = fetch(event.getMetadata()).collect(Collectors.toList())
8991
.onErrorResume(s -> Mono.just(List.of()));
9092

93+
Map<String, Long> routeIdToIdxMap = getRoutes().index()
94+
.collectMap(t -> t.getT2().getId(), Tuple2::getT1)
95+
.block();
96+
9197
scopedRoutes.subscribe(scopedRoutesList -> {
9298
updateCache(Flux.concat(Flux.fromIterable(scopedRoutesList), getNonScopedRoutes(event))
93-
.sort(AnnotationAwareOrderComparator.INSTANCE));
99+
.sort(Comparator.comparing(r -> routeIdToIdxMap.getOrDefault(r.getId(), Long.MIN_VALUE)))
100+
.sort(AnnotationAwareOrderComparator.INSTANCE));
94101
}, this::handleRefreshError);
95102
}
96103
else {

0 commit comments

Comments
 (0)