如何从我的 Spring 启动运行状况端点调用另一个 Spring 启动应用程序的运行状况检查?

How can I invoke the health check of another Spring Boot application from within my Spring Boot health endpoint?

我想知道如何调用自定义健康指标:

  1. 在同一个应用程序中
  2. 另一个 Spring 启动应用程序

我的应用程序分为一个基本应用程序(而不是一个配置)A,它实现了几乎所有的功能(没有 main 方法)和另一个应用程序 B(有一个 main 方法 ;-) )具有基本配置作为POM 中的依赖项。

在 A 中,我实现了自定义 HealthIndicator:

@Component
@RequiredArgsConstructor
public class AdapterDownstreamHealthIndicator implements HealthIndicator {

    private RestTemplate restTemplate;
    private String downStreamUrl = "http://localhost:8081/actuator";

    public AdapterDownstreamHealthIndicator(RestTemplate restTemplate, String downStreamUrl) {
        this.restTemplate = restTemplate;
        this.downStreamUrl = downStreamUrl;
    }

    @Override
    public Health health() {
//        try {
//            JsonNode resp = restTemplate.getForObject(downStreamUrl + "/health", JsonNode.class);
//            if (resp.get("status").asText().equalsIgnoreCase("UP")) {
//                System.out.println("JUHUUUUUUUUUUU!!!!");
//                return Health.up().build();
//            }
//        } catch (Exception ex) {
//            return Health.down(ex).build();
//        }
        return Health.down().build();
    }
}

在我的 application.properties 中,我有一些执行器属性:

management.endpoints.web.exposure.include=health,info,prometheus,adapterDownstream
spring.jackson.serialization.INDENT_OUTPUT=true
management.endpoint.health.show-details=always

当我在浏览器中输入 http://localhost:9091/actuator/health/adapterDownstream 时,调试器不会在 health() 方法中停止,我只会显示一个空白页面。

我已经尝试扩展 AbstractHealthIndicator 而不是实现 HealthIndicator 接口。

无法识别自定义运行状况指示器是我做错了什么?

最后我想进行某种深度健康检查来测试我的应用程序中使用的所有组件。也许应该使用 CompositeHealthContributor???

正如我所描述的,我有一个依赖项 A,它有 NO main method 加载到我的应用程序 B 作为 POM 中的依赖项。到目前为止,我尝试在此 dependency/module A.

中实现自定义健康检查 class/the 健康指标

简单的解决方案是添加一个 @ComponentScan(basePackages = "path.to.actuator") 到应用程序的主要方法。