yufeng0528 лет назад: 4
Родитель
Сommit
33b3072b1f

+ 6 - 4
README.md

@@ -6,9 +6,11 @@ spring5_demo
6 6
 spring5 -> webflux ->spring gateway
7 7
 
8 8
 # 版本
9
-2.2.* -> Hoxton
10
-2.1.* -> Greenwich
11
-2.0.* -> Finchley
9
+* 2.2.* -> Hoxton
10
+* 2.1.* -> Greenwich
11
+* 2.0.* -> Finchley
12 12
 
13
-# 参考
13
+# 路由配置参考
14 14
 1. https://www.jianshu.com/p/86660b8b24c4
15
+2. https://www.jdon.com/51642
16
+3. 

+ 6 - 9
src/main/java/com/yaozhitech/spring5/config/RouterConfig.java

@@ -15,23 +15,20 @@ public class RouterConfig {
15 15
 		//@formatter:off
16 16
 		return builder.routes()
17 17
 				.route("path_route", r -> r.path("/city_list.do")
18
+						.filters(f -> f.requestRateLimiter(c -> c.setRateLimiter(redisRateLimiter())))
18 19
 						.uri("https://api.bbztx.com"))
19 20
 				.route("host_route", r -> r.host("*.myhost.org")
20 21
 						.uri("http://httpbin.org"))
21
-//				.route("rewrite_route", r -> r.host("*.rewrite.org")
22
-//						.filters(f -> f.rewritePath("/foo/(?<segment>.*)",
23
-//								"/${segment}"))
24
-//						.uri("http://httpbin.org"))
22
+				.route("rewrite_route", r -> r.path("/city_list")
23
+						.filters(f -> f.rewritePath("city_list",  // rewritePath方法会使用内建的过滤器重写路径
24
+								"city_list.do"))
25
+						.uri("https://api.bbztx.com"))
25 26
 //				.route("hystrix_route", r -> r.host("*.hystrix.org")
26 27
 //						.filters(f -> f.hystrix(c -> c.setName("slowcmd")))
27 28
 //								.uri("http://httpbin.org"))
28 29
 //				.route("hystrix_fallback_route", r -> r.host("*.hystrixfallback.org")
29 30
 //						.filters(f -> f.hystrix(c -> c.setName("slowcmd").setFallbackUri("forward:/hystrixfallback")))
30 31
 //								.uri("http://httpbin.org"))
31
-//				.route("limit_route", r -> r
32
-//					.host("*.limited.org").and().path("/anything/**")
33
-//						.filters(f -> f.requestRateLimiter(c -> c.setRateLimiter(redisRateLimiter())))
34
-//					.uri("http://httpbin.org"))
35 32
 //				.route("websocket_route", r -> r.path("/echo")
36 33
 //					.uri("ws://localhost:9000"))
37 34
 				.build();
@@ -40,6 +37,6 @@ public class RouterConfig {
40 37
 	
41 38
 	@Bean
42 39
 	RedisRateLimiter redisRateLimiter() {
43
-		return new RedisRateLimiter(1, 2);
40
+		return new RedisRateLimiter(2, 4);
44 41
 	}
45 42
 }

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

@@ -6,4 +6,6 @@ spring.redis.port=6279
6 6
 ## Redis服务器连接密码(默认为空)
7 7
 spring.redis.password=bbztx123456
8 8
 # 连接超时时间(毫秒)
9
-spring.redis.timeout=5000
9
+spring.redis.timeout=5000
10
+#日志
11
+logging.level.org.springframework.cloud.gateway=TRACE