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