簡體   English   中英

Spring Boot Actuator:緩存 /actuator/health/readiness 和 /actuator/health/custom 健康檢查結果

[英]Spring Boot Actuator: Caching /actuator/health/readiness and /actuator/health/custom health check results

因此,我將 Spring Boot Actuator 添加到我的應用程序中,並在application.properties屬性management.endpoint.health.cache.time-to-live=120s中指定緩存健康檢查結果。 所以當我調用/actuator/health時,結果被緩存並且很好。

當我調用/actuator/health/readiness或自定義創建的組/actuator/health/deep時,問題就開始了,這個請求結果沒有被緩存。 我瀏覽了Spring 文檔,只找到了主要健康端點的信息,沒有找到特定群體的信息。

所以我的問題是:我錯過了什么嗎? 或者我如何為特定的 spring 引導執行器端點實現緩存?

謝謝

所以我沒有找到開箱即用的解決方案,所以決定使用 AOP 方法 go。

我發現HealthEndpointWebExtension class 管理健康 rest 端點。 這個 class 有兩種健康方法,一種是調用公共/health端點,另一種是調用health/<group name>

所以我圍繞第二種方法創建了 Aspect,它允許我為我需要的端點添加緩存。

@Around("execution(@org.springframework.boot.actuate.endpoint.annotation.ReadOperation * org.springframework.boot.actuate.health.HealthEndpointWebExtension.health(..,java.lang.String...))) && args(.., path)")
public Object cache(ProceedingJoinPoint joinPoint, String... path) throws Throwable {
    // Logic to get cache per endpoint and process if cache specifed.
}

最后application.properties看起來像這樣:

// out of the box
management.endpoint.health.cache.time-to-live=120s 

// customly created properties
management.endpoint.health.group.readiness.cache.time-to-live=60s
management.endpoint.health.group.deep.cache.time-to-live=120s

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM