spring-boot - Spring boot 2 和 AWS DynamoDB 健康端点
问题描述
我正在使用带有 DynamoDB 的 Spring Boot 2。是否可以在 Spring Boot 执行器 /health 端点上公开 dynamoDB 的健康检查?
最近我遇到了我的应用程序无法连接到 DynamoDB 的情况(底层连接 HTTP 池异常)。
解决方案
您应该能够通过定义自定义执行器运行状况指示器来执行此操作,您可以在其中执行 dynamoDb 操作,例如 ListTables。此处记录了自定义指标,此处记录了ListTables 。你应该最终得到类似的东西:
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;
@Component
public class MyHealthIndicator implements HealthIndicator {
@Override
public Health health() {
int errorCode = check(); // perform some specific health check
if (errorCode != 0) {
return Health.down().withDetail("Error Code", errorCode).build();
}
return Health.up().build();
}
}
private int check(){
try{
AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().build();
ListTablesRequest request = new ListTablesRequest();
ListTablesResult response = client.listTables(request);
return 0;
}catch (Exception e){
//log exception?
return -1;
}
}
推荐阅读
- javascript - 链接逻辑运算符与 Array.prototype.indexOf 之间的性能差异是什么
- php - 如何使用其中的 PHP 代码片段组合显示特殊字符
- office365 - 从 Office 365 管理 API 的“客户端 IP”获取位置
- javascript - 组件重新渲染不同步工作
- ios - 提交ios应用到应用商店的登录信息
- xml - 如何仅从 clojure 中的嵌套 XML 中过滤一些值?
- android - 在离子构建中找不到 fontVariationSettings
- swift - 这个 SwiftUI 动画应该只淡出。为什么会向右移动?
- html - 当我在与我的网站路线不同的路线上移动时,页面没有响应,如何解决?
- javascript - 如何检查对象中的键是对象