use of org.springframework.boot.BootstrapRegistry in project spring-cloud-consul by spring-cloud.
the class ConsulRetryBootstrapper method initialize.
@Override
public void initialize(BootstrapRegistry registry) {
if (!RETRY_IS_PRESENT) {
return;
}
registry.registerIfAbsent(RetryProperties.class, context -> context.get(Binder.class).bind(RetryProperties.PREFIX, RetryProperties.class).orElseGet(RetryProperties::new));
registry.registerIfAbsent(RetryTemplate.class, context -> {
RetryProperties properties = context.get(RetryProperties.class);
if (properties.isEnabled()) {
return RetryTemplate.builder().maxAttempts(properties.getMaxAttempts()).exponentialBackoff(properties.getInitialInterval(), properties.getMultiplier(), properties.getMaxInterval()).build();
}
return null;
});
registry.registerIfAbsent(LoaderInterceptor.class, context -> {
RetryTemplate retryTemplate = context.get(RetryTemplate.class);
if (retryTemplate != null) {
return loadContext -> retryTemplate.execute(retryContext -> loadContext.getInvocation().apply(loadContext.getLoaderContext(), loadContext.getResource()));
}
// disabled
return null;
});
}
Aggregations