fix: improve RouteCache tenant route loading logic
- Change from if-else if to separate if statements - Ensure tenant routes are loaded regardless of IsGlobal flag - Add detailed logging for route loading - Fix null check for GetRoute parameters
This commit is contained in:
parent
1b13efffc5
commit
650f2f48e0
@ -129,16 +129,29 @@ public class RouteCache : IRouteCache
|
|||||||
IsGlobal = route.IsGlobal
|
IsGlobal = route.IsGlobal
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 1. 全局路由
|
||||||
if (route.IsGlobal)
|
if (route.IsGlobal)
|
||||||
{
|
{
|
||||||
_globalRoutes[route.ServiceName] = routeInfo;
|
_globalRoutes[route.ServiceName] = routeInfo;
|
||||||
_pathRoutes[pathPattern] = 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<string, RouteInfo>())
|
||||||
[route.ServiceName] = routeInfo;
|
[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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user