6. 领事重试

如果您预计 consul 代理可能偶尔不可用您的应用程序启动,您可以要求它在失败后继续尝试。您需要添加spring-retryspring-boot-starter-aop到你的类路径。默认的行为是重试 6 次,初始退避间隔为 1000 毫秒,后续退避的指数乘数为 1.1。您可以使用以下属性(和其他属性)spring.cloud.consul.retry.*配置属性。这适用于 Spring Cloud Consul Config 和 Discovery 注册。spring-doc.cadn.net.cn

若要完全控制重试,请添加@Bean类型RetryOperationsInterceptorID 为“consulRetryInterceptor”。 Spring 重试有一个RetryInterceptorBuilder这使得创建一个变得容易。