Skip to content
Open
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
38 changes: 38 additions & 0 deletions demo-circuit-breaker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
27 changes: 27 additions & 0 deletions demo-circuit-breaker/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.xkcoding</groupId>
<artifactId>spring-boot-demo</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>

<artifactId>demo-circuit-breaker</artifactId>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>io.github.resilience4j</groupId>
<artifactId>resilience4j-spring-boot2</artifactId>
<version>1.7.0</version>
</dependency>
</dependencies>

</project>
31 changes: 31 additions & 0 deletions demo-circuit-breaker/src/main/java/PaymentCircuitBreaker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,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();
}
}
11 changes: 11 additions & 0 deletions demo-circuit-breaker/src/main/java/PaymentService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import java.net.http.HttpResponse;

public class PaymentService {
public void paymentConfirm(HttpResponse<String> confirms) {

}

public void updateStatus() {

}
}