Search in sources :

Example 6 with MetadataContext

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);
}
Also used : MetadataContext(com.tencent.cloud.metadata.context.MetadataContext) Route(org.springframework.cloud.gateway.route.Route)

Example 7 with MetadataContext

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());
    }
}
Also used : RequestTemplate(feign.RequestTemplate) MethodMetadata(feign.MethodMetadata) MetadataContext(com.tencent.cloud.metadata.context.MetadataContext)

Aggregations

MetadataContext (com.tencent.cloud.metadata.context.MetadataContext)7 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 RequestContext (com.netflix.zuul.context.RequestContext)1 QuotaResponse (com.tencent.polaris.ratelimit.api.rpc.QuotaResponse)1 MethodMetadata (feign.MethodMetadata)1 RequestTemplate (feign.RequestTemplate)1 Route (org.springframework.cloud.gateway.route.Route)1 DataBuffer (org.springframework.core.io.buffer.DataBuffer)1 ServerHttpRequest (org.springframework.http.server.reactive.ServerHttpRequest)1 ServerHttpResponse (org.springframework.http.server.reactive.ServerHttpResponse)1