use of com.tencent.cloud.metadata.context.MetadataContext in project spring-cloud-tencent by Tencent.
the class MetadataFirstScgFilter method doFilter.
@Override
public Mono<Void> doFilter(ServerWebExchange exchange, GatewayFilterChain chain) {
// get request context
Route route = exchange.getAttribute(GATEWAY_ROUTE_ATTR);
// get metadata of current thread
MetadataContext metadataContext = exchange.getAttribute(MetadataConstant.HeaderName.METADATA_CONTEXT);
// TODO 对端命名空间暂时与本地命名空间相同
metadataContext.putSystemMetadata(MetadataConstant.SystemMetadataKey.PEER_NAMESPACE, MetadataContextHolder.get().getSystemMetadata(MetadataConstant.SystemMetadataKey.LOCAL_NAMESPACE));
metadataContext.putSystemMetadata(MetadataConstant.SystemMetadataKey.PEER_SERVICE, route.getId());
metadataContext.putSystemMetadata(MetadataConstant.SystemMetadataKey.PEER_PATH, exchange.getRequest().getURI().getPath());
exchange.getAttributes().put(MetadataConstant.HeaderName.METADATA_CONTEXT, metadataContext);
return chain.filter(exchange);
}
use of com.tencent.cloud.metadata.context.MetadataContext in project spring-cloud-tencent by Tencent.
the class MetadataFirstFeignPlugin method run.
@Override
public void run(PluggableFeignContext context) {
if (context.getTarget() != null && context.getMethod() != null) {
MethodMetadata methodMetadata = PluggableFeignContractHolder.METHOD_METADATA.get(context.getTarget().type().getPackage().getName() + "." + Feign.configKey(context.getTarget().type(), context.getMethod()));
if (methodMetadata == null) {
return;
}
RequestTemplate requestTemplate = methodMetadata.template();
// get metadata of current thread
MetadataContext metadataContext = MetadataContextHolder.get();
// TODO 对端命名空间暂时与本地命名空间相同
MetadataContextHolder.get().putSystemMetadata(MetadataConstant.SystemMetadataKey.PEER_NAMESPACE, metadataContext.getSystemMetadata(MetadataConstant.SystemMetadataKey.LOCAL_NAMESPACE));
MetadataContextHolder.get().putSystemMetadata(MetadataConstant.SystemMetadataKey.PEER_SERVICE, context.getTarget().name());
MetadataContextHolder.get().putSystemMetadata(MetadataConstant.SystemMetadataKey.PEER_PATH, requestTemplate.path());
}
}
Aggregations