Skip to content

Commit 5caacd0

Browse files
committed
feat: fallback 메서드 정의
1 parent bcf31b8 commit 5caacd0

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

apps/commerce-api/src/main/java/com/loopers/application/payment/PaymentFacade.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.loopers.infrastructure.payment.client.PgClient;
44
import com.loopers.interfaces.api.ApiResponse;
55
import com.loopers.interfaces.api.payment.PaymentV1Dto;
6+
import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker;
67
import lombok.RequiredArgsConstructor;
78
import org.springframework.stereotype.Component;
89

@@ -11,11 +12,20 @@
1112
public class PaymentFacade {
1213
private final PgClient pgClient;
1314

14-
public PaymentV1Dto.TransactionResponse pay(String userId, PaymentV1Dto.PaymentRequest request) {
15+
@CircuitBreaker(name = "pgCircuit", fallbackMethod = "fallback")
16+
public PaymentV1Dto.TransactionResponse requestPayment(String userId, PaymentV1Dto.PaymentRequest request) {
1517
ApiResponse<PaymentV1Dto.TransactionResponse> result = pgClient.requestPayment(userId, request);
1618

1719
PaymentV1Dto.TransactionResponse response = result.data();
1820

1921
return response;
2022
}
23+
24+
public PaymentV1Dto.TransactionResponse fallback(String userId, PaymentV1Dto.PaymentRequest request, Throwable throwable) {
25+
return new PaymentV1Dto.TransactionResponse(
26+
null,
27+
PaymentV1Dto.TransactionStatusResponse.FAILED,
28+
"현재 결제 서비스가 불안정합니다. 잠시 후 다시 시도해주세요."
29+
);
30+
}
2131
}

0 commit comments

Comments
 (0)