Created
May 16, 2019 17:49
-
-
Save RobWin/d7adfcca56b717d741bacf5536386532 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@SpringBootApplication | |
@Configuration | |
public class DemoApplication { | |
private EmployeeRepository employeeRepository; | |
private CircuitBreaker circuitBreaker; | |
private Retry retry; | |
public DemoApplication(CircuitBreakerRegistry circuitBreakerRegistry, | |
RetryRegistry retryRegistry, | |
EmployeeRepository employeeRepository){ | |
this.employeeRepository = employeeRepository; | |
this.circuitBreaker = circuitBreakerRegistry.circuitBreaker("employeeBackend"); | |
this.retry = retryRegistry.retry("employeeBackend"); | |
} | |
@Bean | |
RouterFunction<ServerResponse> getAllEmployeesRoute() { | |
return route(GET("/employees"), | |
req -> ok().body(protect(employeeRepository.findAllEmployees()), Employee.class)); | |
} | |
private <T> Flux<T> protect(Flux<T> flux){ | |
return flux | |
.compose(CircuitBreakerOperator.of(circuitBreaker)) | |
.compose(RetryOperator.of(retry)); | |
} | |
public static void main(String[] args) { | |
SpringApplication.run(DemoApplication.class, args); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment