I am working on a spring boot application broken in multiple microservices. I am currently trying to set up a circuit breaker and I do not manage to see it on the actuator.
I tried to set up this function in my AccountController
<code> @PostMapping("/create/{userID}")
@CircuitBreaker(name = "accountService")
public ResponseEntity<Object> createAccount(@RequestBody AccountDTO account, @PathVariable Long userID) {
log.info("Creating account for user ID: {}", userID);
CashUserDTO user = cashUserServiceProxy.findById(userID);
if (user == null) {
log.error("User not found for ID: {}", userID);
return new ResponseEntity<>("No user found.", HttpStatus.BAD_REQUEST);
} else {
AccountDTO createdAccount = accountsService.createAccount(account, userID);
EntityModel<AccountDTO> model = toModel(createdAccount, userID);
return new ResponseEntity<>(model, HttpStatus.OK);
}
}
</code>
<code> @PostMapping("/create/{userID}")
@CircuitBreaker(name = "accountService")
public ResponseEntity<Object> createAccount(@RequestBody AccountDTO account, @PathVariable Long userID) {
log.info("Creating account for user ID: {}", userID);
CashUserDTO user = cashUserServiceProxy.findById(userID);
if (user == null) {
log.error("User not found for ID: {}", userID);
return new ResponseEntity<>("No user found.", HttpStatus.BAD_REQUEST);
} else {
AccountDTO createdAccount = accountsService.createAccount(account, userID);
EntityModel<AccountDTO> model = toModel(createdAccount, userID);
return new ResponseEntity<>(model, HttpStatus.OK);
}
}
</code>
@PostMapping("/create/{userID}")
@CircuitBreaker(name = "accountService")
public ResponseEntity<Object> createAccount(@RequestBody AccountDTO account, @PathVariable Long userID) {
log.info("Creating account for user ID: {}", userID);
CashUserDTO user = cashUserServiceProxy.findById(userID);
if (user == null) {
log.error("User not found for ID: {}", userID);
return new ResponseEntity<>("No user found.", HttpStatus.BAD_REQUEST);
} else {
AccountDTO createdAccount = accountsService.createAccount(account, userID);
EntityModel<AccountDTO> model = toModel(createdAccount, userID);
return new ResponseEntity<>(model, HttpStatus.OK);
}
}
and my application.properties looks like this
<code>spring.application.name=accountService
spring.config.import=optional:configserver:http://localhost:8070/
server.port=8083
management.health.circuitbreakers.enabled=true
management.endpoint.health.show-details=always
management.endpoints.web.exposure.include=health
spring.datasource.url=jdbc:mysql://localhost:3306/cashmate
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=validate
spring.sql.init.mode=never
spring.sql.init.platform=mysql
resilience4j.circuitbreaker.configs.default.register-health-indicator=true
resilience4j.circuitbreaker.instances.accountService.minimum-number-of-calls=5
resilience4j.circuitbreaker.instances.accountService.failure-rate-threshold=70
resilience4j.circuitbreaker.instances.accountService.wait-duration-in-open-state=10000
resilience4j.circuitbreaker.instances.accountService.permitted-number-of-calls-in-half-open-state=1
management.tracing.sampling.probability=1.0
</code>
<code>spring.application.name=accountService
spring.config.import=optional:configserver:http://localhost:8070/
server.port=8083
management.health.circuitbreakers.enabled=true
management.endpoint.health.show-details=always
management.endpoints.web.exposure.include=health
spring.datasource.url=jdbc:mysql://localhost:3306/cashmate
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=validate
spring.sql.init.mode=never
spring.sql.init.platform=mysql
resilience4j.circuitbreaker.configs.default.register-health-indicator=true
resilience4j.circuitbreaker.instances.accountService.minimum-number-of-calls=5
resilience4j.circuitbreaker.instances.accountService.failure-rate-threshold=70
resilience4j.circuitbreaker.instances.accountService.wait-duration-in-open-state=10000
resilience4j.circuitbreaker.instances.accountService.permitted-number-of-calls-in-half-open-state=1
management.tracing.sampling.probability=1.0
</code>
spring.application.name=accountService
spring.config.import=optional:configserver:http://localhost:8070/
server.port=8083
management.health.circuitbreakers.enabled=true
management.endpoint.health.show-details=always
management.endpoints.web.exposure.include=health
spring.datasource.url=jdbc:mysql://localhost:3306/cashmate
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=validate
spring.sql.init.mode=never
spring.sql.init.platform=mysql
resilience4j.circuitbreaker.configs.default.register-health-indicator=true
resilience4j.circuitbreaker.instances.accountService.minimum-number-of-calls=5
resilience4j.circuitbreaker.instances.accountService.failure-rate-threshold=70
resilience4j.circuitbreaker.instances.accountService.wait-duration-in-open-state=10000
resilience4j.circuitbreaker.instances.accountService.permitted-number-of-calls-in-half-open-state=1
management.tracing.sampling.probability=1.0
And the /actuator/health
looks like this
<code>{"status":"UP","components":{"clientConfigServer":{"status":"UP","details":{"propertySources":["configClient"]}},"db":{"status":"UP","details":{"database":"MySQL","validationQuery":"isValid()"}},"discoveryComposite":{"status":"UP","components":{"discoveryClient":{"status":"UP","details":{"services":[]}},"eureka":{"description":"Eureka discovery client has not yet successfully connected to a Eureka server","status":"UP","details":{"applications":{}}}}},"diskSpace":{"status":"UP","details":{"total":290824646656,"free":289731194880,"threshold":10485760,"path":"D:\coding\CashMateCloud\config-server\.","exists":true}},"ping":{"status":"UP"},"reactiveDiscoveryClients":{"status":"UP","components":{"Simple Reactive Discovery Client":{"status":"UP","details":{"services":[]}},"Spring Cloud Eureka Reactive Discovery Client":{"status":"UP","details":{"services":[]}}}},"refreshScope":{"status":"UP"}}}
</code>
<code>{"status":"UP","components":{"clientConfigServer":{"status":"UP","details":{"propertySources":["configClient"]}},"db":{"status":"UP","details":{"database":"MySQL","validationQuery":"isValid()"}},"discoveryComposite":{"status":"UP","components":{"discoveryClient":{"status":"UP","details":{"services":[]}},"eureka":{"description":"Eureka discovery client has not yet successfully connected to a Eureka server","status":"UP","details":{"applications":{}}}}},"diskSpace":{"status":"UP","details":{"total":290824646656,"free":289731194880,"threshold":10485760,"path":"D:\coding\CashMateCloud\config-server\.","exists":true}},"ping":{"status":"UP"},"reactiveDiscoveryClients":{"status":"UP","components":{"Simple Reactive Discovery Client":{"status":"UP","details":{"services":[]}},"Spring Cloud Eureka Reactive Discovery Client":{"status":"UP","details":{"services":[]}}}},"refreshScope":{"status":"UP"}}}
</code>
{"status":"UP","components":{"clientConfigServer":{"status":"UP","details":{"propertySources":["configClient"]}},"db":{"status":"UP","details":{"database":"MySQL","validationQuery":"isValid()"}},"discoveryComposite":{"status":"UP","components":{"discoveryClient":{"status":"UP","details":{"services":[]}},"eureka":{"description":"Eureka discovery client has not yet successfully connected to a Eureka server","status":"UP","details":{"applications":{}}}}},"diskSpace":{"status":"UP","details":{"total":290824646656,"free":289731194880,"threshold":10485760,"path":"D:\coding\CashMateCloud\config-server\.","exists":true}},"ping":{"status":"UP"},"reactiveDiscoveryClients":{"status":"UP","components":{"Simple Reactive Discovery Client":{"status":"UP","details":{"services":[]}},"Spring Cloud Eureka Reactive Discovery Client":{"status":"UP","details":{"services":[]}}}},"refreshScope":{"status":"UP"}}}
please send help.
New contributor
Laurentiu Andoni is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.