|
|
@ -59,11 +59,11 @@ import static com.tencent.cloud.common.constant.ContextConstant.UTF_8;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Service routing entrance.
|
|
|
|
* Service routing entrance.
|
|
|
|
*
|
|
|
|
* <p>
|
|
|
|
* Rule routing needs to rely on request parameters for server filtering.
|
|
|
|
* Rule routing needs to rely on request parameters for server filtering.
|
|
|
|
* The interface cannot obtain the context object of the request granularity,
|
|
|
|
* The interface cannot obtain the context object of the request granularity,
|
|
|
|
* so the routing capability cannot be achieved through ServerListFilter.
|
|
|
|
* so the routing capability cannot be achieved through ServerListFilter.
|
|
|
|
*
|
|
|
|
* <p>
|
|
|
|
* And {@link PolarisRouterServiceInstanceListSupplier#get(Request)} provides the ability to pass in http headers,
|
|
|
|
* And {@link PolarisRouterServiceInstanceListSupplier#get(Request)} provides the ability to pass in http headers,
|
|
|
|
* so routing capabilities are implemented through IRule.
|
|
|
|
* so routing capabilities are implemented through IRule.
|
|
|
|
*
|
|
|
|
*
|
|
|
@ -95,21 +95,23 @@ public class PolarisRouterServiceInstanceListSupplier extends DelegatingServiceI
|
|
|
|
Flux<List<ServiceInstance>> allServers = getDelegate().get();
|
|
|
|
Flux<List<ServiceInstance>> allServers = getDelegate().get();
|
|
|
|
|
|
|
|
|
|
|
|
// 2. filter by router
|
|
|
|
// 2. filter by router
|
|
|
|
|
|
|
|
PolarisRouterContext routerContext = null;
|
|
|
|
|
|
|
|
|
|
|
|
DefaultRequestContext requestContext = (DefaultRequestContext) request.getContext();
|
|
|
|
DefaultRequestContext requestContext = (DefaultRequestContext) request.getContext();
|
|
|
|
PolarisRouterContext key;
|
|
|
|
|
|
|
|
if (requestContext instanceof RequestDataContext) {
|
|
|
|
if (requestContext instanceof RequestDataContext) {
|
|
|
|
key = buildRouterContext(((RequestDataContext) requestContext).getClientRequest().getHeaders());
|
|
|
|
routerContext = buildRouterContext(((RequestDataContext) requestContext).getClientRequest().getHeaders());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (requestContext.getClientRequest() instanceof PolarisLoadBalancerRequest) {
|
|
|
|
else if (requestContext.getClientRequest() instanceof PolarisLoadBalancerRequest) {
|
|
|
|
key = buildRouterContext(((PolarisLoadBalancerRequest<?>) requestContext.getClientRequest()).getRequest()
|
|
|
|
routerContext = buildRouterContext(((PolarisLoadBalancerRequest<?>) requestContext.getClientRequest()).getRequest()
|
|
|
|
.getHeaders());
|
|
|
|
.getHeaders());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
|
|
|
|
if (routerContext == null) {
|
|
|
|
// return all servers if router context is null.
|
|
|
|
// return all servers if router context is null.
|
|
|
|
return allServers;
|
|
|
|
return allServers;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return doRouter(allServers, key);
|
|
|
|
return doRouter(allServers, routerContext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//set method to public for unit test
|
|
|
|
//set method to public for unit test
|
|
|
|