Dynamic change plugins of route

This commit is contained in:
hongqiaowei
2021-10-13 11:14:46 +08:00
parent 396a8f81f7
commit 81341bd62e
3 changed files with 15 additions and 8 deletions

View File

@@ -22,6 +22,7 @@ import org.springframework.web.server.WebFilterChain;
import reactor.core.publisher.Mono;
import we.Fizz;
import we.FizzAppContext;
import we.proxy.Route;
import we.util.ReactorUtils;
import we.util.WebUtils;
@@ -44,11 +45,13 @@ public final class FizzPluginFilterChain {
public static Mono<Void> next(ServerWebExchange exchange) {
Iterator<PluginConfig> it = exchange.getAttribute(pluginConfigsIt);
if (it == null) {
List<PluginConfig> pcs = WebUtils.getRoute(exchange).pluginConfigs;
Route route = WebUtils.getRoute(exchange);
if (it == null || route.pluginConfigsChange) {
List<PluginConfig> pcs = route.pluginConfigs;
it = pcs.iterator();
Map<String, Object> attris = exchange.getAttributes();
attris.put(pluginConfigsIt, it);
route.pluginConfigsChange = false;
}
if (it.hasNext()) {
PluginConfig pc = it.next();
@@ -86,7 +89,7 @@ public final class FizzPluginFilterChain {
}
}
// @Deprecated
@Deprecated
public static Mono<Void> next(ServerWebExchange exchange, List<PluginConfig> pcs) {
Iterator<PluginConfig> it = pcs.iterator();
Map<String, Object> attris = exchange.getAttributes();

View File

@@ -227,7 +227,7 @@ public class ApiConfig {
.backendService(this.backendService)
.backendPath( this.backendPath)
.query( WebUtils.getClientReqQuery(exchange))
.pluginConfigs( this.pluginConfigs)
// .pluginConfigs( this.pluginConfigs)
.rpcMethod( this.rpcMethod)
.rpcParamTypes( this.rpcParamTypes)
.rpcGroup( this.rpcGroup)
@@ -236,6 +236,7 @@ public class ApiConfig {
.retryCount( this.retryCount)
.retryInterval( this.retryInterval);
r.pluginConfigs = this.pluginConfigs;
if (this.type == Type.REVERSE_PROXY) {
r = r.nextHttpHostPort(getNextHttpHostPort());
}

View File

@@ -44,6 +44,8 @@ public class Route {
public List<PluginConfig> pluginConfigs;
public boolean pluginConfigsChange = false;
public String rpcMethod;
public String rpcParamTypes;
@@ -85,6 +87,7 @@ public class Route {
public Route pluginConfigs(List<PluginConfig> pcs) {
pluginConfigs = pcs;
pluginConfigsChange = true;
return this;
}