Merge pull request #62 from Development-team-1/api_gateway_rate_limiter
api gateway redis rate limiter 적용
This commit is contained in:
@@ -23,7 +23,7 @@ ext {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.springframework.cloud:spring-cloud-starter-circuitbreaker-resilience4j'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-data-redis-reactive'
|
||||
implementation 'org.springframework.cloud:spring-cloud-starter-gateway'
|
||||
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
|
||||
// https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt
|
||||
|
||||
@@ -4,8 +4,11 @@ import com.justpickup.customerapigatewayservice.handler.GlobalExceptionHandler;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.web.reactive.error.ErrorWebExceptionHandler;
|
||||
import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
|
||||
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableEurekaClient
|
||||
@@ -20,4 +23,8 @@ public class CustomerApigatewayServiceApplication {
|
||||
return new GlobalExceptionHandler();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public KeyResolver tokenKeyResolver() {
|
||||
return exchange -> Mono.just(exchange.getRequest().getHeaders().get(HttpHeaders.AUTHORIZATION).get(0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,11 @@ spring:
|
||||
filters:
|
||||
- AuthorizationHeaderFilter
|
||||
- RewritePath=/order-service/(?<segment>.*),/$\{segment}
|
||||
|
||||
- name: RequestRateLimiter
|
||||
args:
|
||||
redis-rate-limiter.replenishRate: 3
|
||||
redis-rate-limiter.burstCapacity: 3
|
||||
key-resolver: "#{@tokenKeyResolver}"
|
||||
- id: store-service
|
||||
uri: lb://STORE-SERVICE
|
||||
predicates:
|
||||
@@ -69,6 +73,11 @@ spring:
|
||||
filters:
|
||||
- AuthorizationHeaderFilter
|
||||
- RewritePath=/store-service/(?<segment>.*),/$\{segment}
|
||||
- name: RequestRateLimiter
|
||||
args:
|
||||
redis-rate-limiter.replenishRate: 3
|
||||
redis-rate-limiter.burstCapacity: 3
|
||||
key-resolver: "#{@tokenKeyResolver}"
|
||||
|
||||
- id: notification-service
|
||||
uri: lb://NOTIFICATION-SERVICE
|
||||
|
||||
@@ -23,7 +23,8 @@ ext {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.springframework.cloud:spring-cloud-starter-circuitbreaker-resilience4j'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-data-redis-reactive'
|
||||
|
||||
implementation 'org.springframework.cloud:spring-cloud-starter-gateway'
|
||||
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
|
||||
// https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt
|
||||
|
||||
@@ -4,8 +4,11 @@ import com.justpickup.ownerapigatewayservice.handler.GlobalExceptionHandler;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.web.reactive.error.ErrorWebExceptionHandler;
|
||||
import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
|
||||
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableEurekaClient
|
||||
@@ -20,4 +23,9 @@ public class OwnerApigatewayServiceApplication {
|
||||
return new GlobalExceptionHandler();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public KeyResolver tokenKeyResolver() {
|
||||
return exchange -> Mono.just(exchange.getRequest().getHeaders().get(HttpHeaders.AUTHORIZATION).get(0));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -55,7 +55,11 @@ spring:
|
||||
filters:
|
||||
- AuthorizationHeaderFilter
|
||||
- RewritePath=/order-service/(?<segment>.*),/$\{segment}
|
||||
|
||||
- name: RequestRateLimiter
|
||||
args:
|
||||
redis-rate-limiter.replenishRate: 3
|
||||
redis-rate-limiter.burstCapacity: 3
|
||||
key-resolver: "#{@tokenKeyResolver}"
|
||||
- id: store-service
|
||||
uri: lb://STORE-SERVICE
|
||||
predicates:
|
||||
@@ -63,7 +67,11 @@ spring:
|
||||
filters:
|
||||
- AuthorizationHeaderFilter
|
||||
- RewritePath=/store-service/(?<segment>.*),/$\{segment}
|
||||
|
||||
- name: RequestRateLimiter
|
||||
args:
|
||||
redis-rate-limiter.replenishRate: 3
|
||||
redis-rate-limiter.burstCapacity: 3
|
||||
key-resolver: "#{@tokenKeyResolver}"
|
||||
- id: notification-service
|
||||
uri: lb://NOTIFICATION-SERVICE
|
||||
predicates:
|
||||
|
||||
Reference in New Issue
Block a user