我最近将我的应用程序配置为使用 Spring Cloud Config 和 Github 作为配置存储库。
- Spring Boot - 2.1.1.RELEASE
- Spring Cloud 依赖项 - Greenwich.RC2
我的应用程序几乎使用了开箱即用的所有内容。我刚刚配置了数据库application.yml
我有 HikariCP 自动配置在后台发挥魔力。
我正在使用这个调用的作业刷新我的应用程序refresh()
方法上的刷新端点.
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.endpoint.RefreshEndpoint;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@EnableScheduling
@Component
public class ConfigRefreshJob {
private static final Logger LOG = LoggerFactory.getLogger(ConfigRefreshJob.class);
private static final int ONE_MINUTE = 60 * 1000;
private final RefreshEndpoint refreshEndpoint;
@Autowired
public ConfigRefreshJob(final RefreshEndpoint refreshEndpoint) {
this.refreshEndpoint = refreshEndpoint;
}
@Scheduled(fixedDelay = ONE_MINUTE)
public void refreshConfigs() {
LOG.info("Refreshing Configurations - {}", refreshEndpoint.refresh());
}
}
一切似乎都运行良好,但每次刷新配置时我都会看到以下日志。这些日志显示 HikariCP 池已关闭并在每次刷新时启动。
2019-01-16 18:54:55.817 INFO 14 --- [taskScheduler-9] o.s.b.SpringApplication : Started application in 0.155 seconds (JVM running for 144.646)
2019-01-16 18:54:55.828 INFO 14 --- [taskScheduler-9] c.z.h.HikariDataSource : HikariPool-1555 - Shutdown initiated...
2019-01-16 18:54:55.828 INFO 14 --- [taskScheduler-9] c.z.h.HikariDataSource : HikariPool-1555 - Shutdown completed.
2019-01-16 18:54:55.828 INFO 14 --- [taskScheduler-9] c.d.ConfigRefreshJob : Refreshing Configurations - []
2019-01-16 18:55:03.094 INFO 14 --- [ XNIO-1 task-5] c.z.h.HikariDataSource : HikariPool-1556 - Starting...
2019-01-16 18:55:03.123 INFO 14 --- [ XNIO-1 task-5] c.z.h.HikariDataSource : HikariPool-1556 - Start completed.
如果我查看这些日志的时间,HikariCP 再次配置大约需要 8 秒。
到目前为止,我还没有在我的应用程序中发现任何问题,因为应用程序上的负载现在还没有那么多,但这里有几个问题。
-
HikariCP 的重新启动是否会导致应用程序负载增加的问题?
-
如果重启会导致问题,有没有办法不刷新 HikariCP?
HikariCP 默认情况下可刷新,因为对其进行的更改会在池启动后密封配置。
所以禁用这个,设置spring.cloud.refresh.refreshable
到一个空集。
这是在yaml中配置的示例
spring:
cloud:
refresh:
refreshable:
- com.example.app.config.ConfigProperties
where ConfigProperties
是带有注释的类@RefreshScope
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)