-
Notifications
You must be signed in to change notification settings - Fork 12.3k
Expand file tree
/
Copy pathPaymentCircuitBreaker.java
More file actions
31 lines (22 loc) · 918 Bytes
/
PaymentCircuitBreaker.java
File metadata and controls
31 lines (22 loc) · 918 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker;
import java.io.IOException;
import java.net.*;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class PaymentCircuitBreaker {
PaymentService service = new PaymentService();
@CircuitBreaker(name = "updateOrder", fallbackMethod = "paymentAuthorizedPendingIntegration")
public void paymentConfirm() throws IOException, InterruptedException {
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("http://example.com/payment-confirm"))
.build();
HttpResponse<String> response = client.send(request,
HttpResponse.BodyHandlers.ofString());
service.paymentConfirm(response);
}
public void paymentAuthorizedPendingIntegration(Long id, Exception e) {
service.updateStatus();
}
}