将信息从Endpoint传递到自定义运行状况指示器

问题描述 投票:0回答:1

我已经创建了一个Spring Boot Actuator端点,我需要将一些信息从该端点传递到我已实现的自定义健康指标之一。下面的代码段是我的终点。现在假设我在调用此端点时传递了一个字符串作为标头。现在,我希望将此标头依次传递到我创建的自定义健康点。我该如何实现?

据我了解,HealthEndpoint包含有关弹簧执行器默认提供的健康指标以及我们实施的自定义健康指标的信息。

@Component
@Endpoint(id = "healthcheck")
public class HealthCheckEndpoint {

    private final HealthEndpoint healthEndpoint;

    @Autowired
    public HealthCheckEndpoint(HealthEndpoint healthEndpoint) {
        this.healthEndpoint = healthEndpoint;
    }

    @ReadOperation(produces = "application/json")
    public Health getHealthJson() {
        Health health = healthEndpoint.health();
        // Pass some information to one of the custom health indicators.
        return health;
    }

}
java spring-boot spring-boot-actuator health-monitoring
1个回答
0
投票

您可以使用@RequestHeader批注从请求中获取标头值。

import org.springframework.web.bind.annotation.RequestHeader;
@ReadOperation(produces = "application/json")
    public Health getHealthJson(@RequestHeader(value = "customHeader") String customHeader) {
        Health health = healthEndpoint.health();
        // Pass some information to one of the custom health indicators.
        return health;
    }
© www.soinside.com 2019 - 2024. All rights reserved.