Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public RouteLocator gatewayRoutes(RouteLocatorBuilder builder) {
.filters(f -> addCircuitBreaker(f, "userServiceCircuitBreaker", "default"))
.uri("lb://user"))
.route("performance-service", r -> r.path("/api/v1/performances/**", "/api/v1/schedules/**", "/api/v1/seats/**")
.filters(f -> addCircuitBreaker(f, "performanceServiceCircuitBreaker", "default"))
.filters(f -> f.filter(queueCheckFilter::filter)
.circuitBreaker(c -> c.setName("performanceServiceCircuitBreaker")
.setFallbackUri("forward:/fallback/default")))
.uri("lb://performance"))
.route("order-service", r -> r.path("/api/v1/orders/**")
.filters(f -> f.filter(queueCheckFilter::filter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,28 @@

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpMethod;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.util.AntPathMatcher;

@Slf4j
@Getter
@RequiredArgsConstructor
public enum ApiType {

ENTER_WAITING_QUEUE("/api/v1/waiting-queue", HttpMethod.POST),
GET_QUEUE_INFO("/api/v1/waiting-queue", HttpMethod.GET),
CREATE_ORDER("/api/v1/orders", HttpMethod.POST);
PRE_RESERVE_SEAT("/api/v1/seats/**/pre-reserve", HttpMethod.POST),
CREATE_ORDER("/api/v1/orders", HttpMethod.POST),
VALIDATE_ORDER("/api/v1/orders/**/validate", HttpMethod.POST);

private final String path;
private final HttpMethod method;

private static final AntPathMatcher pathMatcher = new AntPathMatcher();

public static Mono<ApiType> findByRequest(String requestPath, String httpMethod) {
return Flux.fromArray(ApiType.values())
.filter(api -> api.matches(requestPath, httpMethod))
Expand All @@ -25,7 +32,7 @@ public static Mono<ApiType> findByRequest(String requestPath, String httpMethod)
}

private boolean matches(String requestPath, String httpMethod) {
return requestPath.equals(this.path) && this.method.name().equals(httpMethod);
return pathMatcher.match(this.path, requestPath) && this.method.name().equals(httpMethod);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
switch (api) {
case ENTER_WAITING_QUEUE -> handleEnterWaitingQueueApi(exchange, chain);
case GET_QUEUE_INFO -> handleGetQueueInfoApi(exchange, chain);
case CREATE_ORDER -> handleCreateOrderApi(exchange, chain);
case PRE_RESERVE_SEAT, CREATE_ORDER, VALIDATE_ORDER -> handleCreateOrderApi(exchange, chain);
})
.switchIfEmpty(chain.filter(exchange));
}
Expand Down
Loading