使用Spring Boot實現動態健康檢查HealthChecks
import org.springframework.boot.SpringApplication; import org.springframework.boot.actuate.health.Health; import org.springframework.boot.actuate.health.HealthIndicator; import org.springframework.boot.actuate.health.HealthIndicatorRegistry; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @SpringBootApplication public class App { public static void main(String[] args) { SpringApplication.run(App.class, args); } } /** * <pre> * {@code * curl -X PUT http://localhost:8080/healthchecks/gugu * curl -X PUT http://localhost:8080/healthchecks/gaga * * curl http://localhost:8080/actuator/health * * curl -X DELETE http://localhost:8080/healthchecks/gaga * } * </pre> */ @RestController @RequestMapping("healthchecks") @RequiredArgsConstructor class HealthController { private final HealthIndicatorRegistry registry; @PutMapping("/{name}") public void addHealthCheck(@PathVariable String name) { registry.register(name, new DynamicHealthCheck(name)); } @DeleteMapping("/{name}") public void removeHealthCheck(@PathVariable String name) { registry.unregister(name); } } @Slf4j @RequiredArgsConstructor class DynamicHealthCheck implements HealthIndicator { private final String name; @Override public Health health() { log.info("check health for: {}", name); return Health.up().build(); } } |
application.properties
management.endpoint.health.show-details=ALWAYS
相關文章
- 系統健康檢查利器-Spring Boot-ActuatorSpring Boot
- Java 框架:Spring Boot 2.6健康檢查帶來新功能Java框架Spring Boot
- Spring Boot中使用JPA構建動態查詢Spring Boot
- Oracle SCN健康狀態檢查Oracle
- 在.NET Core 中實現健康檢查
- Spring Boot Admin實現服務健康預警Spring Boot
- spring boot+bootstrap實現動態輪播圖實戰Spring Boot
- Docker 容器的健康狀態檢查Docker
- LVS - 使用用Keepalived實現健康檢查的示例
- Java後端分散式系統的服務健康檢查:Spring Boot HealthJava後端分散式Spring Boot
- Spring Boot 如何熱載入 jar 實現動態外掛?Spring BootJAR
- Spring Boot 如何熱載入jar實現動態外掛?Spring BootJAR
- 使用 Spring Boot 3.2 和 CRaC 實現更快啟動Spring Boot
- 使用Spring Boot實現模組化Spring Boot
- 如何在 ASP.Net Core 中實現 健康檢查ASP.NET
- 使用Spring Boot實現的GraphQL示例Spring Boot
- 使用Spring Boot實現事務管理Spring Boot
- Spring Boot動態許可權變更實現的整體方案Spring Boot
- Spring Boot 使用Apollo動態調整日誌級別Spring Boot
- DB健康檢查使用RDA收集資料
- Spring Boot 2.0(二):Spring Boot 2.0嚐鮮-動態 BannerSpring Boot
- EntityFramework Core健康檢查Framework
- Health Monitor 健康檢查
- spring-boot-route(二十一)quartz實現動態定時任務Springbootquartz
- 使用Spring Boot和Kafka Streams實現CQRSSpring BootKafka
- 使用JWT實現Spring Boot令牌認證JWTSpring Boot
- 使用Spring Boot實現訊息佇列Spring Boot佇列
- 使用Spring Boot實現分散式事務Spring Boot分散式
- 如何在Java服務中實現自動化的健康檢查與自愈機制Java
- 使用Spring Session實現Spring Boot水平擴充套件SessionSpring Boot套件
- [譯] 實時通訊:使用 Spring Boot 實現 WebSocketSpring BootWeb
- 使用Spring Data JPA實現DDD聚合的動態投影Spring
- 使用Vue+Spring Boot實現Excel上傳VueSpring BootExcel
- 使用Spring Boot實現Redis事務 | VinsguruSpring BootRedis
- 使用Spring Boot實現檔案上傳功能Spring Boot
- 使用Elasticsearch實現Spring Boot的自動完成功能 -Milos BiljanovicElasticsearchSpring Boot
- SOFABoot 健康檢查能力分析boot
- django 動態查詢實現過程Django