Skip to content

Instantly share code, notes, and snippets.

@RobWin
Created May 16, 2019 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RobWin/d7adfcca56b717d741bacf5536386532 to your computer and use it in GitHub Desktop.
Save RobWin/d7adfcca56b717d741bacf5536386532 to your computer and use it in GitHub Desktop.
@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