Consul 重试
如果您预期在应用启动时,Consul 代理可能偶尔不可用,可以要求它在失败后继续尝试。您需要将 spring-retry 和 spring-boot-starter-aspectj 添加到类路径中。默认行为是重试 6 次,初始退避间隔为 1000 毫秒,后续退避的指数乘数为 1.1。您可以使用 spring.cloud.consul.retry.* 配置属性来配置这些属性(以及其他属性)。这适用于 Spring Cloud Consul Config 和 Discovery 注册。
提示
要完全控制重试机制,请添加一个类型为 RetryOperationsInterceptor、id 为 "consulRetryInterceptor" 的 @Bean。Spring Retry 提供了 RetryInterceptorBuilder,可以轻松创建此类拦截器。