【问题标题】:Is it possible to change Actuator health api response structure to custom response是否可以将执行器健康 API 响应结构更改为自定义响应
【发布时间】:2021-03-10 11:41:11
【问题描述】:

我为不同的数据库编写了 healthIndicator,这些数据库从 spring 扩展了 AbstractHealthIndicator。

但最终消费者期望响应采用不同格式,其中预期的公共键和数据不同。

实际:

{
    "status": "DOWN",
    "details": {
        "B": {
            "status": "UP",
            "details": {
                "reachable": true
            }
        },
        "A": {
            "status": "DOWN",
            "details": {
                "reachable": false
            }
        }
    }
}

预期:

{
    "result": true,
    "data": {
        "modules": [
            {
              "name": "A",
              "status": "OK"
            },
            {
                "name": "B",
                "status": "DOWN"
            },
        ]
    }
}

有没有可能写一个转换器,可以做到这一点?

【问题讨论】:

    标签: spring spring-boot spring-boot-actuator


    【解决方案1】:

    我认为您不能在不更改内部执行器代码的情况下更改 /health 端点的格式。

    但是,可以创建自己的端点来维护对 Health 端点的引用(毕竟它是一个 bean,因此可以注入),以便其 @GetOperation 将调用原始的“health”端点,获取结果并将其转换为您的自定义格式。

    原来的Health Endpoint实现in this class

    【讨论】:

      猜你喜欢
      • 2020-12-19
      • 2020-04-11
      • 2019-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多