Dynamic change plugins of route
This commit is contained in:
@@ -22,6 +22,7 @@ import org.springframework.web.server.WebFilterChain;
|
|||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
import we.Fizz;
|
import we.Fizz;
|
||||||
import we.FizzAppContext;
|
import we.FizzAppContext;
|
||||||
|
import we.proxy.Route;
|
||||||
import we.util.ReactorUtils;
|
import we.util.ReactorUtils;
|
||||||
import we.util.WebUtils;
|
import we.util.WebUtils;
|
||||||
|
|
||||||
@@ -44,11 +45,13 @@ public final class FizzPluginFilterChain {
|
|||||||
|
|
||||||
public static Mono<Void> next(ServerWebExchange exchange) {
|
public static Mono<Void> next(ServerWebExchange exchange) {
|
||||||
Iterator<PluginConfig> it = exchange.getAttribute(pluginConfigsIt);
|
Iterator<PluginConfig> it = exchange.getAttribute(pluginConfigsIt);
|
||||||
if (it == null) {
|
Route route = WebUtils.getRoute(exchange);
|
||||||
List<PluginConfig> pcs = WebUtils.getRoute(exchange).pluginConfigs;
|
if (it == null || route.pluginConfigsChange) {
|
||||||
|
List<PluginConfig> pcs = route.pluginConfigs;
|
||||||
it = pcs.iterator();
|
it = pcs.iterator();
|
||||||
Map<String, Object> attris = exchange.getAttributes();
|
Map<String, Object> attris = exchange.getAttributes();
|
||||||
attris.put(pluginConfigsIt, it);
|
attris.put(pluginConfigsIt, it);
|
||||||
|
route.pluginConfigsChange = false;
|
||||||
}
|
}
|
||||||
if (it.hasNext()) {
|
if (it.hasNext()) {
|
||||||
PluginConfig pc = it.next();
|
PluginConfig pc = it.next();
|
||||||
@@ -86,7 +89,7 @@ public final class FizzPluginFilterChain {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Deprecated
|
@Deprecated
|
||||||
public static Mono<Void> next(ServerWebExchange exchange, List<PluginConfig> pcs) {
|
public static Mono<Void> next(ServerWebExchange exchange, List<PluginConfig> pcs) {
|
||||||
Iterator<PluginConfig> it = pcs.iterator();
|
Iterator<PluginConfig> it = pcs.iterator();
|
||||||
Map<String, Object> attris = exchange.getAttributes();
|
Map<String, Object> attris = exchange.getAttributes();
|
||||||
|
|||||||
@@ -227,7 +227,7 @@ public class ApiConfig {
|
|||||||
.backendService(this.backendService)
|
.backendService(this.backendService)
|
||||||
.backendPath( this.backendPath)
|
.backendPath( this.backendPath)
|
||||||
.query( WebUtils.getClientReqQuery(exchange))
|
.query( WebUtils.getClientReqQuery(exchange))
|
||||||
.pluginConfigs( this.pluginConfigs)
|
// .pluginConfigs( this.pluginConfigs)
|
||||||
.rpcMethod( this.rpcMethod)
|
.rpcMethod( this.rpcMethod)
|
||||||
.rpcParamTypes( this.rpcParamTypes)
|
.rpcParamTypes( this.rpcParamTypes)
|
||||||
.rpcGroup( this.rpcGroup)
|
.rpcGroup( this.rpcGroup)
|
||||||
@@ -236,6 +236,7 @@ public class ApiConfig {
|
|||||||
.retryCount( this.retryCount)
|
.retryCount( this.retryCount)
|
||||||
.retryInterval( this.retryInterval);
|
.retryInterval( this.retryInterval);
|
||||||
|
|
||||||
|
r.pluginConfigs = this.pluginConfigs;
|
||||||
if (this.type == Type.REVERSE_PROXY) {
|
if (this.type == Type.REVERSE_PROXY) {
|
||||||
r = r.nextHttpHostPort(getNextHttpHostPort());
|
r = r.nextHttpHostPort(getNextHttpHostPort());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,8 @@ public class Route {
|
|||||||
|
|
||||||
public List<PluginConfig> pluginConfigs;
|
public List<PluginConfig> pluginConfigs;
|
||||||
|
|
||||||
|
public boolean pluginConfigsChange = false;
|
||||||
|
|
||||||
public String rpcMethod;
|
public String rpcMethod;
|
||||||
|
|
||||||
public String rpcParamTypes;
|
public String rpcParamTypes;
|
||||||
@@ -52,11 +54,11 @@ public class Route {
|
|||||||
|
|
||||||
public String rpcGroup;
|
public String rpcGroup;
|
||||||
|
|
||||||
public long timeout = 0;
|
public long timeout = 0;
|
||||||
|
|
||||||
public int retryCount = 0;
|
public int retryCount = 0;
|
||||||
|
|
||||||
public long retryInterval = 0;
|
public long retryInterval = 0;
|
||||||
|
|
||||||
public Route type(int t) {
|
public Route type(int t) {
|
||||||
type = (byte) t;
|
type = (byte) t;
|
||||||
@@ -84,7 +86,8 @@ public class Route {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Route pluginConfigs(List<PluginConfig> pcs) {
|
public Route pluginConfigs(List<PluginConfig> pcs) {
|
||||||
pluginConfigs = pcs;
|
pluginConfigs = pcs;
|
||||||
|
pluginConfigsChange = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user