use of com.tencent.cloud.polaris.router.PolarisRouterContext in project spring-cloud-tencent by Tencent.
the class PolarisFeignLoadBalancer method customizeLoadBalancerCommandBuilder.
@Override
protected void customizeLoadBalancerCommandBuilder(RibbonRequest request, IClientConfig config, LoadBalancerCommand.Builder<RibbonResponse> builder) {
Map<String, Collection<String>> headers = request.getRequest().headers();
PolarisRouterContext routerContext = buildRouterContext(headers);
builder.withServerLocator(routerContext);
}
use of com.tencent.cloud.polaris.router.PolarisRouterContext in project spring-cloud-tencent by Tencent.
the class PolarisFeignLoadBalancer method buildRouterContext.
// set method to public for unit test
PolarisRouterContext buildRouterContext(Map<String, Collection<String>> headers) {
Collection<String> labelHeaderValues = headers.get(RouterConstants.ROUTER_LABEL_HEADER);
if (CollectionUtils.isEmpty(labelHeaderValues)) {
return null;
}
PolarisRouterContext routerContext = new PolarisRouterContext();
routerContext.setLabels(PolarisRouterContext.TRANSITIVE_LABELS, MetadataContextHolder.get().getFragmentContext(MetadataContext.FRAGMENT_TRANSITIVE));
labelHeaderValues.forEach(labelHeaderValue -> {
Map<String, String> labels = JacksonUtils.deserialize2Map(labelHeaderValue);
if (!CollectionUtils.isEmpty(labels)) {
Map<String, String> unescapeLabels = new HashMap<>(labels.size());
for (Map.Entry<String, String> entry : labels.entrySet()) {
String escapedKey = ExpressionLabelUtils.unescape(entry.getKey());
String escapedValue = ExpressionLabelUtils.unescape(entry.getValue());
unescapeLabels.put(escapedKey, escapedValue);
}
routerContext.setLabels(PolarisRouterContext.RULE_ROUTER_LABELS, unescapeLabels);
}
});
return routerContext;
}
Aggregations