|
|
@@ -0,0 +1,28 @@
|
|
|
+package com.inspur.smsb.gateway.config;
|
|
|
+
|
|
|
+import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
|
|
|
+import org.springframework.context.annotation.Bean;
|
|
|
+import org.springframework.context.annotation.Configuration;
|
|
|
+import reactor.core.publisher.Mono;
|
|
|
+
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 路由限流配置
|
|
|
+ *
|
|
|
+ * @author liangke
|
|
|
+ */
|
|
|
+@Configuration(proxyBeanMethods = false)
|
|
|
+public class RateLimiterConfiguration {
|
|
|
+ /**
|
|
|
+ * Remote address key resolver.
|
|
|
+ *
|
|
|
+ * @link {https://docs.spring.io/spring-cloud-gateway/docs/current/reference/html/#the-requestratelimiter-gatewayfilter-factory}
|
|
|
+ */
|
|
|
+ @Bean
|
|
|
+ public KeyResolver remoteAddrKeyResolver() {
|
|
|
+ return exchange -> Mono
|
|
|
+ .just(Objects.requireNonNull(Objects.requireNonNull(exchange.getRequest().getRemoteAddress()))
|
|
|
+ .getAddress().getHostAddress());
|
|
|
+ }
|
|
|
+}
|