diff --git a/src/yarpgateway/Services/RouteCache.cs b/src/yarpgateway/Services/RouteCache.cs index 0656d01..bb2cb44 100644 --- a/src/yarpgateway/Services/RouteCache.cs +++ b/src/yarpgateway/Services/RouteCache.cs @@ -129,16 +129,29 @@ public class RouteCache : IRouteCache IsGlobal = route.IsGlobal }; + // 1. 全局路由 if (route.IsGlobal) { _globalRoutes[route.ServiceName] = routeInfo; _pathRoutes[pathPattern] = routeInfo; + _logger.LogDebug("Loaded global route: {Service} -> {Cluster}", + route.ServiceName, route.ClusterId); } - else if (!string.IsNullOrEmpty(route.TenantCode)) + + // 2. 租户专属路由(无论 IsGlobal 值如何,只要有 TenantCode 就添加到租户路由表) + if (!string.IsNullOrEmpty(route.TenantCode)) { - _tenantRoutes.GetOrAdd(route.TenantCode, _ => new()) + _tenantRoutes.GetOrAdd(route.TenantCode, _ => new ConcurrentDictionary()) [route.ServiceName] = routeInfo; - _pathRoutes[pathPattern] = routeInfo; + + // 如果不是全局路由,也添加到路径路由 + if (!route.IsGlobal) + { + _pathRoutes[pathPattern] = routeInfo; + } + + _logger.LogDebug("Loaded tenant route: {Tenant}/{Service} -> {Cluster}", + route.TenantCode, route.ServiceName, route.ClusterId); } } }