【问题标题】:Spring boot 2 and AWS DynamoDB health endpointSpring boot 2 和 AWS DynamoDB 健康端点
【发布时间】:2019-05-29 20:48:19
【问题描述】:

我正在使用带有 DynamoDB 的 Spring Boot 2。是否可以在 Spring Boot 执行器 /health 端点上公开 dynamoDB 的健康检查?

最近我的应用程序无法连接到 DynamoDB(底层连接 HTTP 池异常)。

【问题讨论】:

    标签: spring-boot amazon-dynamodb


    【解决方案1】:

    您应该能够通过定义自定义执行器运行状况指示器来执行此操作,您可以在其中执行 dynamoDb 操作,例如 ListTables。 自定义指标记录在 here 和 ListTables here。 你应该得到类似的结果:

    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;
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-26
      • 2023-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多