RetryConfiguration { @Bean public RetryRegistry retryRegistry(RetryConfigurationProperties retryConfigurationProperties, EventConsumerRegistry<RetryEvent> retryEventConsumerRegistry, RegistryEventConsumer<Retry> retryRegistryEventConsumer, @Qualifier("compositeRetryCustomizer") CompositeCustomizer<RetryConfigCustomizer> compositeRetryCustomizer) { RetryRegistry retryRegistry = createRetryRegistry(retryConfigurationProperties, retryRegistryEventConsumer, compositeRetryCustomizer); registerEventConsumer(retryRegistry, retryEventConsumerRegistry, retryConfigurationProperties); retryConfigurationProperties.getInstances() .forEach((name, properties) -> retryRegistry.retry(name, retryConfigurationProperties .createRetryConfig(name, compositeRetryCustomizer))); return retryRegistry; }  @Bean @Qualifier("compositeRetryCustomizer") CompositeCustomizer<RetryConfigCustomizer> compositeRetryCustomizer(
        @Autowired(required = false) List<RetryConfigCustomizer> configCustomizers); @Bean RetryRegistry retryRegistry(RetryConfigurationProperties retryConfigurationProperties,
        EventConsumerRegistry<RetryEvent> retryEventConsumerRegistry,
        RegistryEventConsumer<Retry> retryRegistryEventConsumer,
        @Qualifier("compositeRetryCustomizer") CompositeCustomizer<RetryConfigCustomizer> compositeRetryCustomizer); @Bean @Primary RegistryEventConsumer<Retry> retryRegistryEventConsumer(
        Optional<List<RegistryEventConsumer<Retry>>> optionalRegistryEventConsumers); @Bean @Conditional(value = {AspectJOnClasspathCondition.class}) RetryAspect retryAspect(
        RetryConfigurationProperties retryConfigurationProperties,
        RetryRegistry retryRegistry,
        @Autowired(required = false) List<RetryAspectExt> retryAspectExtList,
        FallbackDecorators fallbackDecorators,
        SpelResolver spelResolver
    ); @Bean @Conditional(value = {RxJava2OnClasspathCondition.class, AspectJOnClasspathCondition.class}) RxJava2RetryAspectExt rxJava2RetryAspectExt(); @Bean @Conditional(value = {ReactorOnClasspathCondition.class, AspectJOnClasspathCondition.class}) ReactorRetryAspectExt reactorRetryAspectExt(); @Bean EventConsumerRegistry<RetryEvent> retryEventConsumerRegistry();  }
@Test public void testRetryRegistry() { InstanceProperties instanceProperties1 = new InstanceProperties(); instanceProperties1.setMaxRetryAttempts(3); InstanceProperties instanceProperties2 = new InstanceProperties(); instanceProperties2.setMaxRetryAttempts(2); RetryConfigurationProperties retryConfigurationProperties = new RetryConfigurationProperties(); retryConfigurationProperties.getInstances().put("backend1", instanceProperties1); retryConfigurationProperties.getInstances().put("backend2", instanceProperties2); retryConfigurationProperties.setRetryAspectOrder(200); RetryConfiguration retryConfiguration = new RetryConfiguration(); DefaultEventConsumerRegistry<RetryEvent> eventConsumerRegistry = new DefaultEventConsumerRegistry<>(); RetryRegistry retryRegistry = retryConfiguration .retryRegistry(retryConfigurationProperties, eventConsumerRegistry, new CompositeRegistryEventConsumer<>(emptyList()), compositeRetryCustomizerTest()); assertThat(retryConfigurationProperties.getRetryAspectOrder()).isEqualTo(200); assertThat(retryRegistry.getAllRetries().size()).isEqualTo(2); Retry retry1 = retryRegistry.retry("backend1"); assertThat(retry1).isNotNull(); assertThat(retry1.getRetryConfig().getMaxAttempts()).isEqualTo(3); Retry retry2 = retryRegistry.retry("backend2"); assertThat(retry2).isNotNull(); assertThat(retry2.getRetryConfig().getMaxAttempts()).isEqualTo(2); assertThat(eventConsumerRegistry.getAllEventConsumer()).hasSize(2); }
@Test public void testCreateRetryRegistryWithSharedConfigs() { InstanceProperties defaultProperties = new InstanceProperties(); defaultProperties.setMaxRetryAttempts(3); defaultProperties.setWaitDuration(Duration.ofMillis(100L)); InstanceProperties sharedProperties = new InstanceProperties(); sharedProperties.setMaxRetryAttempts(2); sharedProperties.setWaitDuration(Duration.ofMillis(100L)); InstanceProperties backendWithDefaultConfig = new InstanceProperties(); backendWithDefaultConfig.setBaseConfig("default"); backendWithDefaultConfig.setWaitDuration(Duration.ofMillis(200L)); InstanceProperties backendWithSharedConfig = new InstanceProperties(); backendWithSharedConfig.setBaseConfig("sharedConfig"); backendWithSharedConfig.setWaitDuration(Duration.ofMillis(300L)); RetryConfigurationProperties retryConfigurationProperties = new RetryConfigurationProperties(); retryConfigurationProperties.getConfigs().put("default", defaultProperties); retryConfigurationProperties.getConfigs().put("sharedConfig", sharedProperties); retryConfigurationProperties.getInstances() .put("backendWithDefaultConfig", backendWithDefaultConfig); retryConfigurationProperties.getInstances() .put("backendWithSharedConfig", backendWithSharedConfig); RetryConfiguration retryConfiguration = new RetryConfiguration(); DefaultEventConsumerRegistry<RetryEvent> eventConsumerRegistry = new DefaultEventConsumerRegistry<>(); RetryRegistry retryRegistry = retryConfiguration .retryRegistry(retryConfigurationProperties, eventConsumerRegistry, new CompositeRegistryEventConsumer<>(emptyList()), compositeRetryCustomizerTest()); assertThat(retryRegistry.getAllRetries().size()).isEqualTo(2); Retry retry1 = retryRegistry.retry("backendWithDefaultConfig"); assertThat(retry1).isNotNull(); assertThat(retry1.getRetryConfig().getMaxAttempts()).isEqualTo(3); assertThat(retry1.getRetryConfig().getIntervalFunction().apply(1)).isEqualTo(200L); Retry retry2 = retryRegistry.retry("backendWithSharedConfig"); assertThat(retry2).isNotNull(); assertThat(retry2.getRetryConfig().getMaxAttempts()).isEqualTo(2); assertThat(retry2.getRetryConfig().getIntervalFunction().apply(1)).isEqualTo(300L); Retry retry3 = retryRegistry.retry("unknownBackend"); assertThat(retry3).isNotNull(); assertThat(retry3.getRetryConfig().getMaxAttempts()).isEqualTo(3); assertThat(eventConsumerRegistry.getAllEventConsumer()).hasSize(3); }
@Test public void testCreateRetryRegistryWithUnknownConfig() { RetryConfigurationProperties retryConfigurationProperties = new RetryConfigurationProperties(); InstanceProperties instanceProperties = new InstanceProperties(); instanceProperties.setBaseConfig("unknownConfig"); retryConfigurationProperties.getInstances().put("backend", instanceProperties); RetryConfiguration retryConfiguration = new RetryConfiguration(); DefaultEventConsumerRegistry<RetryEvent> eventConsumerRegistry = new DefaultEventConsumerRegistry<>(); assertThatThrownBy(() -> retryConfiguration .retryRegistry(retryConfigurationProperties, eventConsumerRegistry, new CompositeRegistryEventConsumer<>(emptyList()), compositeRetryCustomizerTest())) .isInstanceOf(ConfigurationNotFoundException.class) .hasMessage("Configuration with name 'unknownConfig' does not exist"); }