Springboot监控之一:SpringBoot四大神器之Actuator之2--spring boot健康检查对Redis的连接检查的调整
因为项目里面用到了redis集群,但并不是用spring boot的配置方式,启动后项目健康检查老是检查redis的时候状态为down,导致注册到eureka后项目状态也是down。
问下能不能设置spring boot不检查 redis的健康状态
"redis": {
"status": "DOWN",
"error": "org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool"
}
而且,应用的控制台上也会输出如下:
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused: connect
at redis.clients.jedis.Connection.connect(Connection.java:207)
at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:93)
at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1767)
at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:106)
at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:888)
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:432)
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:361)
at redis.clients.util.Pool.getResource(Pool.java:49)
... 95 common frames omitted
原因分析
如提问者所述,由于在Spring Boot项目中引用了Redis模块,所以Spring Boot Actuator会对其进行健康检查,正常情况下不会出现问题,但是由于采用了其他配置方式,导致redis的连接检查没有通过。这样就会导致了Consul或Eureka的HealthCheck认为该服务是DOWN状态。
那么redis的健康检查是如何实现的呢?我们不妨来看看健康检查的自动化配置中针对redis的配置源码:
@Configuration |
以上内容取自:org.springframework.boot.actuate.autoconfigure.HealthIndicatorAutoConfiguration类。从自动化配置中我们可以看到,会自动加载一个针对redis的HealthIndicator实现,并且该Bean命名为redisHealthIndicator。
解决方法
通过上面的分析,我们已经知道了是哪个Bean导致了服务实例的健康检查不通过,那么如何解决该问题的方法也就马上能想到了:我们只需要再实现一个redis的HealthIndicator实现来替代原先默认的检查逻辑。比如:
@Component |
上面通过实现HealthIndicator接口中的health方法,直接返回了up状态。通过@Component注解,让Spring Boot扫描到该类就能自动的进行加载,并覆盖原来的redis健康检查实现。当然,这里的实现并不好,因为它只是为了让健康检查可以通过,但是并没有做真正的健康检查。如提问者所说,采用了其他配置访问,那么正确的做法就是在health方法中实现针对其他配置的内容进行健康检查。
注意:这里隐含了一个实现命名的问题,由于默认的bean名称会使用redisHealthIndicator,所以这里的定义可以替换默认的实现,因为它的名字与@ConditionalOnMissingBean(name = "redisHealthIndicator")中的命名一致。但是如果您自定义的实现类并非叫RedisHealthIndicator,它的默认名称与自动化配置的名称是不匹配的,那么就不会替换,这个时候需要在@Component注解中指定该Bean的名称为redisHealthIndicator。
Springboot监控之一:SpringBoot四大神器之Actuator之2--spring boot健康检查对Redis的连接检查的调整的更多相关文章
- Springboot监控之一:SpringBoot四大神器之Actuator之3-springBoot的监控和管理--指标说明
Spring Boot包含很多其他的特性,它们可以帮你监控和管理发布到生产环境的应用.你可以选择使用HTTP端点,JMX或远程shell(SSH或Telnet)来管理和监控应用.审计(Auditing ...
- Springboot监控之一:SpringBoot四大神器之Actuator
介绍 Spring Boot有四大神器,分别是auto-configuration.starters.cli.actuator,本文主要讲actuator.actuator是spring boot提供 ...
- Springboot监控之一:SpringBoot四大神器之Actuator之2--springboot健康检查
Health 信息是从 ApplicationContext 中所有的 HealthIndicator 的 Bean 中收集的, Spring Boot 内置了一些 HealthIndicator. ...
- Spring Boot]SpringBoot四大神器之Actuator
论文转载自博客: https://blog.csdn.net/Dreamhai/article/details/81077903 https://bigjar.github.io/2018/08/19 ...
- SpringBoot四大神器之Actuator
介绍 Spring Boot有四大神器,分别是auto-configuration.starters.cli.actuator,本文主要讲actuator.actuator是spring boot提供 ...
- Springboot监控之一:SpringBoot四大神器之Actuator之2--覆盖修改spring cloud的默认的consul健康检查规则
微服务网关是socket长连接与支付公司对接,该网关需要提供http接口给内部系统调用,当socket没有建立连接时(网关服务的高可用是haProxy搭建的,有些服务的socket可能未连上支付公司) ...
- SpringBoot四大神器之Starter
SpringBoot的starter主要用来简化依赖用的.本文主要分两部分,一部分是列出一些starter的依赖,另一部分是教你自己写一个starter. 部分starters的依赖 Starter( ...
- SpringBoot四大神器之auto-configuration
SpringBoot 自动配置主要通过 @EnableAutoConfiguration, @Conditional, @EnableConfigurationProperties 或者 @Confi ...
- Spring Boot (四): Druid 连接池密码加密与监控
在上一篇文章<Spring Boot (三): ORM 框架 JPA 与连接池 Hikari> 我们介绍了 JPA 与连接池 Hikari 的整合使用,在国内使用比较多的连接池还有一个是阿 ...
随机推荐
- win7 32位下载安装redis并安装php_redis扩展
redis打包文件下载地址:http://files.cnblogs.com/files/cuiwenyuan/Redis-3.2.100-Windows-32.zip php_redis.dll下载 ...
- 存储过程 & 触发器
触发器主要是通过事件进行触发而被执行的,而存储过程可以通过存储过程名字而被直接调用.当对某一表进行诸如UPDATE. INSERT. DELETE 这些操作时, 就会自动执行触发器所定义的SQL 语句 ...
- activiti 基础搭建
首先在eclipse内添加activiti的插件,https://blog.csdn.net/qq_22701869/article/details/79537971 1.创建一个maven的java ...
- 第7条:用列表推导式来取代map和filter
核心知识点: 1.列表推导式要比内置的map和filter函数清晰,因为它无需额外编写lambda表达式. 2.列表推导式可以跳过输入列表中的某些元素,如果改用map来做,那就必须辅以filter方能 ...
- static_func
<?php function testing() { static $a = 1; $a *= 2; echo $a."\n"; } testing(); testing() ...
- Oracle数据库体系结构(4)oracle控制文件
控制文件的概述 1.控制文件是oracle数据库非常重要的物理文件,描述了整个数据库的物理结构信息,包括数据库名称.数据文件与重做日志文件的名称与位置,日志序列号等信息.数据库实例根据初始化参数CON ...
- Data Structure Binary Tree: Construct Full Binary Tree from given preorder and postorder traversals
http://www.geeksforgeeks.org/full-and-complete-binary-tree-from-given-preorder-and-postorder-travers ...
- 【leetcode刷题笔记】Decode Ways
A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' - ...
- 第二十二篇、IO多路复用 一
一.简介io多路复用 可以监听多个文件描述符(socket对象)(文件句柄),一旦文件句柄出现变化,就会感知到 Linux中的 select,poll,epoll(内核2.6以上) 都是IO多路复用的 ...
- runtime 实现方法交换 viewwillappear方法
1.新建分类 #import "UIViewController+swizzling.h"#import <objc/runtime.h> @implementatio ...