dongyukun
9 天以前 e88fba9645a57535d858ce48da8e9d9a3dc84adc
提交 | 用户 | 时间
e7c126 1 package com.iailab.framework.tenant.core.rpc;
H 2
3 import com.iailab.framework.tenant.core.context.TenantContextHolder;
4 import com.iailab.framework.web.core.util.WebFrameworkUtils;
5 import feign.RequestInterceptor;
6 import feign.RequestTemplate;
7
8 import static com.iailab.framework.web.core.util.WebFrameworkUtils.HEADER_TENANT_ID;
9
10 /**
11  * Tenant 的 RequestInterceptor 实现类:Feign 请求时,将 {@link TenantContextHolder} 设置到 header 中,继续透传给被调用的服务
12  *
13  * @author iailab
14  */
15 public class TenantRequestInterceptor implements RequestInterceptor {
16
17     @Override
18     public void apply(RequestTemplate requestTemplate) {
19         Long tenantId = TenantContextHolder.getTenantId();
20         if (tenantId != null) {
21             requestTemplate.header(HEADER_TENANT_ID, String.valueOf(tenantId));
22         }
23     }
24
25 }