第三方 API 的执行器健康检查
Actuator Healthcheck for Third party APIs
假设我有一个 API 调用另一个
API 并且我也想对此端点进行健康检查。这可以用 Actuator 实现还是我需要编写自定义代码?
您可以通过实施 org.springframework.boot.actuate.health.HealthIndicator
并将其作为 bean 添加到 spring 上下文中来实施自定义健康指标。像下面这样的东西应该让你开始:
@Component
public class CustomHealthCheck implements HealthIndicator {
@Override
public Health health() {
int errorCode = check();
if (errorCode != 0) {
return Health.down()
.withDetail("Error Code", errorCode).build();
}
return Health.up().build();
}
public int check() {
// Custom logic to check health
return 0;
}
}
假设我有一个 API 调用另一个 API 并且我也想对此端点进行健康检查。这可以用 Actuator 实现还是我需要编写自定义代码?
您可以通过实施 org.springframework.boot.actuate.health.HealthIndicator
并将其作为 bean 添加到 spring 上下文中来实施自定义健康指标。像下面这样的东西应该让你开始:
@Component
public class CustomHealthCheck implements HealthIndicator {
@Override
public Health health() {
int errorCode = check();
if (errorCode != 0) {
return Health.down()
.withDetail("Error Code", errorCode).build();
}
return Health.up().build();
}
public int check() {
// Custom logic to check health
return 0;
}
}