【发布时间】:2018-05-11 22:53:33
【问题描述】:
SQS 是否有 Spring Boot Actuator Health Check 端点?我已经建立了一个 SQS 消费者,我想检查 SQS 是否已启动并正在运行。我没有使用 JMSlistener 连接到 SQS,而是使用 Spring Cloud Libraries。
我实现了以下健康检查端点。当我删除队列并尝试点击运行状况检查端点时,这将返回以下错误。如果存在连接问题或 SQS 服务出现故障,我是否会收到类似的错误,最终导致运行状况检查端点失败?
com.amazonaws.services.sqs.model.QueueDoesNotExistException: 此 wsdl 版本不存在指定的队列。 (服务: 亚马逊SQS;状态码:400;错误代码: AWS.SimpleQueueService.NonExistentQueue;请求编号: cd8e205d-dc43-535e-931f-7332733bd16c)
public class SqsQueueHealthIndicator extends AbstractHealthIndicator {
private final AmazonSQSAsync amazonSQSAsync;
private final String queueName;
public SqsQueueHealthIndicator(AmazonSQSAsync amazonSQSAsync, String queueName) {
this.amazonSQSAsync = amazonSQSAsync;
this.queueName = queueName;
}
@Override
protected void doHealthCheck(Health.Builder builder) {
try {
amazonSQSAsync.getQueueUrl(queueName);
builder.up();
} catch (QueueDoesNotExistException e) {
e.printStackTrace();
builder.down(e);
}
}
}
豆类
@Bean
SqsQueueHealthIndicator queueHealthIndicator(@Autowired AmazonSQSAsync amazonSQSAsync, @Value("${sqs.queueName}") String queueName) {
return new SqsQueueHealthIndicator(amazonSQSAsync, queueName);
}
@Bean
SqsQueueHealthIndicator deadLetterQueueHealthIndicator(@Autowired AmazonSQSAsync amazonSQSAsync, @Value("${sqs.dlQueueName}") String deadLetterQueueName) {
return new SqsQueueHealthIndicator(amazonSQSAsync, deadLetterQueueName);
}
【问题讨论】:
标签: java spring amazon-web-services spring-boot spring-boot-actuator