1.custom define WebClient.Builder; 2. support gateway group check by application name
This commit is contained in:
@@ -31,9 +31,7 @@ import org.springframework.web.reactive.function.client.WebClient;
|
|||||||
import reactor.netty.http.client.HttpClient;
|
import reactor.netty.http.client.HttpClient;
|
||||||
import reactor.netty.tcp.TcpClient;
|
import reactor.netty.tcp.TcpClient;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import javax.net.ssl.SSLException;
|
import javax.net.ssl.SSLException;
|
||||||
import java.time.Duration;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -127,10 +125,7 @@ public abstract class WebClientConfig {
|
|||||||
// @Resource
|
// @Resource
|
||||||
// ReactorClientHttpConnector reactorClientHttpConnector;
|
// ReactorClientHttpConnector reactorClientHttpConnector;
|
||||||
|
|
||||||
@Resource
|
public WebClient webClient(WebClient.Builder webClientBuilder) {
|
||||||
WebClient.Builder webClientBuilder;
|
|
||||||
|
|
||||||
public WebClient webClient() {
|
|
||||||
|
|
||||||
HttpClient httpClient = HttpClient.create()
|
HttpClient httpClient = HttpClient.create()
|
||||||
.tcpConfiguration(
|
.tcpConfiguration(
|
||||||
|
|||||||
@@ -17,12 +17,11 @@
|
|||||||
|
|
||||||
package we.config;
|
package we.config;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.web.reactive.function.client.WebClient;
|
import org.springframework.web.reactive.function.client.WebClient;
|
||||||
import reactor.netty.resources.LoopResources;
|
|
||||||
import we.util.JacksonUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author hongqiaowei
|
* @author hongqiaowei
|
||||||
@@ -35,10 +34,16 @@ public class ProxyWebClientConfig extends WebClientConfig {
|
|||||||
protected static final String prefix = "proxy-webclient";
|
protected static final String prefix = "proxy-webclient";
|
||||||
|
|
||||||
public static final String proxyWebClient = "proxyWebClient";
|
public static final String proxyWebClient = "proxyWebClient";
|
||||||
|
public static final String proxyWebClientBuilder = "proxyWebClientBuilder";
|
||||||
|
|
||||||
|
@Bean(proxyWebClientBuilder)
|
||||||
|
public WebClient.Builder webClientBuilder() {
|
||||||
|
return WebClient.builder();
|
||||||
|
}
|
||||||
|
|
||||||
@Bean(proxyWebClient)
|
@Bean(proxyWebClient)
|
||||||
public WebClient webClient() {
|
public WebClient webClient(@Qualifier("proxyWebClientBuilder") WebClient.Builder builder) {
|
||||||
log.info(proxyWebClient + ": " + this);
|
log.info(proxyWebClient + ": " + this);
|
||||||
return super.webClient();
|
return super.webClient(builder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,12 +19,13 @@ package we.plugin.auth;
|
|||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.data.redis.core.ReactiveStringRedisTemplate;
|
import org.springframework.data.redis.core.ReactiveStringRedisTemplate;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import reactor.core.publisher.Flux;
|
import reactor.core.publisher.Flux;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
import we.flume.clients.log4j2appender.LogService;
|
|
||||||
import we.config.AggregateRedisConfig;
|
import we.config.AggregateRedisConfig;
|
||||||
|
import we.flume.clients.log4j2appender.LogService;
|
||||||
import we.util.Constants;
|
import we.util.Constants;
|
||||||
import we.util.JacksonUtils;
|
import we.util.JacksonUtils;
|
||||||
import we.util.NetworkUtils;
|
import we.util.NetworkUtils;
|
||||||
@@ -60,6 +61,9 @@ public class GatewayGroupService {
|
|||||||
@Resource(name = AggregateRedisConfig.AGGREGATE_REACTIVE_REDIS_TEMPLATE)
|
@Resource(name = AggregateRedisConfig.AGGREGATE_REACTIVE_REDIS_TEMPLATE)
|
||||||
private ReactiveStringRedisTemplate rt;
|
private ReactiveStringRedisTemplate rt;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private Environment environment;
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() throws Throwable {
|
public void init() throws Throwable {
|
||||||
this.init(this::lsnGatewayGroupChange);
|
this.init(this::lsnGatewayGroupChange);
|
||||||
@@ -181,10 +185,11 @@ public class GatewayGroupService {
|
|||||||
private void updateCurrentGatewayGroupSet(Set<String> currentGatewayGroupSet, Map<String,
|
private void updateCurrentGatewayGroupSet(Set<String> currentGatewayGroupSet, Map<String,
|
||||||
GatewayGroup> gatewayGroupMap) {
|
GatewayGroup> gatewayGroupMap) {
|
||||||
String ip = NetworkUtils.getServerIp();
|
String ip = NetworkUtils.getServerIp();
|
||||||
|
String applicationName = environment.getProperty("spring.application.name");
|
||||||
currentGatewayGroupSet.clear();
|
currentGatewayGroupSet.clear();
|
||||||
gatewayGroupMap.forEach(
|
gatewayGroupMap.forEach(
|
||||||
(k, gg) -> {
|
(k, gg) -> {
|
||||||
if (gg.gateways.contains(ip)) {
|
if (gg.gateways.contains(ip) || gg.gateways.contains(applicationName)) {
|
||||||
currentGatewayGroupSet.add(gg.group);
|
currentGatewayGroupSet.add(gg.group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user