|
|
@@ -1,9 +1,12 @@
|
|
|
package com.kxs.system.api.feign.config;
|
|
|
|
|
|
+import cn.hutool.core.text.CharSequenceUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import com.kxs.common.core.constant.ServiceNameConstants;
|
|
|
import com.kxs.system.api.feign.*;
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import org.springframework.cloud.client.loadbalancer.reactive.ReactorLoadBalancerExchangeFilterFunction;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
@@ -16,7 +19,9 @@ import org.springframework.web.service.invoker.HttpServiceProxyFactory;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
|
- * 当前服务的webClient配置 服务下的远程调用统一在此配置
|
|
|
+ * 当前服务的webClient配置
|
|
|
+ * 服务下的远程调用统一在此配置
|
|
|
+ * 使用注册中心 需配置远程调用器 以实现负载均衡
|
|
|
* </p>
|
|
|
*
|
|
|
* @author 没秃顶的码农
|
|
|
@@ -26,7 +31,12 @@ import org.springframework.web.service.invoker.HttpServiceProxyFactory;
|
|
|
@RequiredArgsConstructor
|
|
|
public class AdminFeignClientConfiguration {
|
|
|
|
|
|
- private static final String ADMIN_SERVICE = "http://localhost:8888";
|
|
|
+ /**
|
|
|
+ * 负载均衡器
|
|
|
+ */
|
|
|
+ private final ReactorLoadBalancerExchangeFilterFunction reactorLoadBalancerExchangeFilterFunction;
|
|
|
+
|
|
|
+ private static final String SERVICE_NAME = ServiceNameConstants.CLIENT_NAME + ServiceNameConstants.SYSTEM_SERVICE;
|
|
|
|
|
|
@Bean
|
|
|
public WebClient oauthRequestInterceptor() {
|
|
|
@@ -42,14 +52,14 @@ public class AdminFeignClientConfiguration {
|
|
|
if (requestAttributes != null) {
|
|
|
HttpServletRequest httpServletRequest = requestAttributes.getRequest();
|
|
|
String token = httpServletRequest.getHeader(HttpHeaders.AUTHORIZATION);
|
|
|
- if (!StrUtil.isBlank(token)) {
|
|
|
+ if (!CharSequenceUtil.isBlank(token)) {
|
|
|
// 传递token
|
|
|
filtered.header(HttpHeaders.AUTHORIZATION, token);
|
|
|
}
|
|
|
}
|
|
|
return next.exchange(filtered.build());
|
|
|
- })
|
|
|
- .baseUrl(ADMIN_SERVICE)
|
|
|
+ }).filter(reactorLoadBalancerExchangeFilterFunction)
|
|
|
+ .baseUrl(SERVICE_NAME)
|
|
|
.build();
|
|
|
}
|
|
|
|