yufeng0528 4 years ago
parent
commit
3875b176ab

+ 4 - 0
README.md

@@ -34,6 +34,10 @@ spring5 -> webflux ->spring gateway
34 34
 16. CircuitBreaker
35 35
 17. ...
36 36
 
37
+## 全局过滤器
38
+1. ReactiveLoadBalancerClientFilter
39
+2. Gateway Metrics 
40
+3. 
37 41
 
38 42
 
39 43
 

+ 35 - 0
src/main/java/com/yaozhitech/spring5/config/FilterConfig.java

@@ -0,0 +1,35 @@
1
+package com.yaozhitech.spring5.config;
2
+
3
+import org.springframework.cloud.gateway.filter.GatewayFilterChain;
4
+import org.springframework.cloud.gateway.filter.GlobalFilter;
5
+import org.springframework.context.annotation.Bean;
6
+import org.springframework.context.annotation.Configuration;
7
+import org.springframework.core.Ordered;
8
+import org.springframework.web.server.ServerWebExchange;
9
+
10
+import lombok.extern.slf4j.Slf4j;
11
+import reactor.core.publisher.Mono;
12
+
13
+@Configuration
14
+@Slf4j
15
+public class FilterConfig {
16
+
17
+	@Bean
18
+	public GlobalFilter customFilter() {
19
+	    return new CustomGlobalFilter();
20
+	}
21
+
22
+	public class CustomGlobalFilter implements GlobalFilter, Ordered {
23
+
24
+	    @Override
25
+	    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
26
+	        log.info("custom global filter");
27
+	        return chain.filter(exchange);
28
+	    }
29
+
30
+	    @Override
31
+	    public int getOrder() {
32
+	        return -1;
33
+	    }
34
+	}
35
+}

+ 7 - 1
src/main/resources/application.properties

@@ -11,4 +11,10 @@ spring.redis.timeout=5000
11 11
 logging.level.org.springframework.cloud=debug
12 12
 #hystrix
13 13
 hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 4000
14
-# hystrix.command.apiTimeOut.execution.isolation.thread.timeoutInMilliseconds: 2000
14
+# hystrix.command.apiTimeOut.execution.isolation.thread.timeoutInMilliseconds: 2000
15
+#度量
16
+spring.cloud.gateway.metrics.enabled=true
17
+# 开启指定端点
18
+management.endpoints.web.exposure.include=gateway,metrics
19
+
20
+