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