update - 客户端 feign 添加 header 信息

This commit is contained in:
wangli 2024-06-28 17:33:28 +08:00
parent ac0d23ee65
commit f2b49ebfbc
2 changed files with 8 additions and 3 deletions

View File

@ -5,6 +5,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.util.StringUtils;
import javax.annotation.Nullable;
@ -199,8 +200,8 @@ public class WorkflowEngineClientAutoConfiguration {
}
@Bean
public RequestInterceptor workflowRequestInterceptor(String serviceVersion) {
return new WorkflowRequestInterceptor(serviceVersion);
public RequestInterceptor workflowRequestInterceptor(String serviceVersion, Environment environment) {
return new WorkflowRequestInterceptor(serviceVersion, environment);
}
}

View File

@ -3,6 +3,7 @@ package cn.axzo.workflow.client.config;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import feign.Target;
import org.springframework.core.env.Environment;
/**
* 通用的 Feign 请求拦截器
@ -12,9 +13,11 @@ import feign.Target;
*/
public class WorkflowRequestInterceptor implements RequestInterceptor {
private final String serviceVersion;
private final Environment environment;
public WorkflowRequestInterceptor(String serviceVersion) {
public WorkflowRequestInterceptor(String serviceVersion, Environment environment) {
this.serviceVersion = serviceVersion;
this.environment = environment;
}
public static final String HEADER_HTTP_CLIENT = "http-client";
@ -31,6 +34,7 @@ public class WorkflowRequestInterceptor implements RequestInterceptor {
|| apiClassPath.contains("cn.axzo.workflow.client.feign.manage")) {
requestTemplate.header(HEADER_HTTP_CLIENT, HEADER_HTTP_CLIENT_VALUE);
requestTemplate.header(HEADER_API_VERSION, serviceVersion);
requestTemplate.header(HEADER_SERVER_NAME, environment.getProperty("spring.application.name"));
}
}
}