Код: Выделить всё
@Bean
RouteLocator routesConfig(RouteLocatorBuilder builder) {
//Part of code is omitted for conciseness
return builder.routes()
.route(p -> p.path("/isoft-bank/accounts/**")
.filters(f ->
f.rewritePath("/isoft-bank/accounts/(?.*)", restPattern)
.addResponseHeader(xResponseTime, currDate)
.circuitBreaker(config -> config
.setName("accountsCB")
.setFallbackUri(callSupport)))
.uri("lb://ACCOUNTS"))
.build();
}
Код: Выделить всё
//Part of config-server.yml omitted for conciseness
resilience4j:
circuitbreaker:
configs:
default:
sliding-window-size: 5
sliding-window-type: time_based
permitted-number-of-calls-in-half-open-state: 2
failure-rate-threshold: 50
wait-duration-in-open-state: 10000
record-exceptions:
- java.lang.Throwable
accountsCB:
sliding-window-size: 10
sliding-window-type: count_based
permitted-number-of-calls-in-half-open-state: 3
failure-rate-threshold: 45
wait-duration-in-open-state: 8000
record-exceptions:
- java.lang.Throwable
Код: Выделить всё
@RestController
@RequestMapping("")
public class FallBackController {
@RequestMapping("/callSupport")
public Mono callSupport() {
return Mono.just("something went wrong,if the problem persists call (+098) 123 456 789");
}
}
Код: Выделить всё
http://localhost:8100/isoft-bank/accounts/api/v1/get-customer-details?mobileNumber=09123123213
Код: Выделить всё
public CustomerDetailsDTO getCustomerDetails(@Pattern(regexp = "^[0-9]{11}$", message = "please provide a valid mobile number") String mobileNumber,
@RequestHeader String correlationId) {
CustomerDTO customerDTO = customerService.findByMobileNumber(mobileNumber);
AccountDTO accountDTO = accountService.findByCustomerId(customerDTO.getId());
CardsDto cardsDto = cardsClient.getCardsDetail(mobileNumber, correlationId).getBody();
LoansDto loansDto = loansClient.getLoanDetails(mobileNumber, correlationId).getBody();
//custom exception throwing for testing purpose
if (true) throw new RuntimeException("ALIII");
return CustomerMapper.CustomerDetailsMapper.get().toDTO(customerDTO, accountDTO, cardsDto, loansDto);
}
Код: Выделить всё
@ExceptionHandler({Exception.class})
public ResponseEntity globalExceptionsHandler(Exception e, WebRequest webRequest) throws Exception {
if (true)
throw e;
else
return this.getResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR.value(), webRequest, e);
}
Код: Выделить всё
{
"timestamp": "2024-11-05T11:53:55.117+00:00",
"status": 500,
"error": "Internal Server Error",
"path": "/api/v1/get-customer-details"
}
также, когда я вызываю http://localhost:8100/actuator/circuitbreakerevents, этот запрос считается успешным:
Код: Выделить всё
[
{
"circuitBreakerName": "accountsCB",
"type": "SUCCESS",
"creationTime": "2024-11-05T16:03:17.720247700+03:30[Asia/Tehran]",
"errorMessage": null,
"durationInMs": 31,
"stateTransition": null
}
]
Подробнее здесь: https://stackoverflow.com/questions/791 ... s-recorded