diff --git a/spring-cloud-stream-core-docs/src/main/asciidoc/spring-cloud-stream-overview.adoc b/spring-cloud-stream-core-docs/src/main/asciidoc/spring-cloud-stream-overview.adoc index 0f67be74b..10bf4102a 100644 --- a/spring-cloud-stream-core-docs/src/main/asciidoc/spring-cloud-stream-overview.adoc +++ b/spring-cloud-stream-core-docs/src/main/asciidoc/spring-cloud-stream-overview.adoc @@ -844,7 +844,7 @@ essentially allowing you to build your own re-try logic within the handler itsel ===== Retry Template The `RetryTemplate` is part of the https://github.com/spring-projects/spring-retry[Spring Retry] library. -While it is out of scope of this dcument to cover all of the capabilities of the `RetryTemplate`, we will mention the following consumer properties that are specifically related to +While it is out of scope of this document to cover all of the capabilities of the `RetryTemplate`, we will mention the following consumer properties that are specifically related to the `RetryTemplate`: maxAttempts:: @@ -865,8 +865,18 @@ The backoff multiplier. Default 2.0. While the preceding settings are sufficient for majority of the customization requirements, they may not satisfy certain complex requirements at, which -point you may want to provide your own instance of the `RetryTemplate`. To do so configure it as a `@Bean` in your application configuration. The application provided -instance overrides the one provided by the framework. +point you may want to provide your own instance of the `RetryTemplate`. To do so configure it as a bean in your application configuration. The application provided +instance will override the one provided by the framework. Also, to avoid conflicts you must qualify the instance of the `RetryTemplate` you want to be used by the binder +as `@StreamRetryTemplate`. For example, + +[source,java] +---- +@StreamRetryTemplate +public RetryTemplate myRetryTemplate() { + return new RetryTemplate(); +} +---- +As you can see from the above example you don't need to annotate it with `@Bean` since `@StreamRetryTemplate` is a qualified `@Bean`. [[spring-cloud-stream-overview-reactive-programming-support]] === Reactive Programming Support diff --git a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/annotation/StreamRetryTemplate.java b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/annotation/StreamRetryTemplate.java new file mode 100644 index 000000000..6c8f042ec --- /dev/null +++ b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/annotation/StreamRetryTemplate.java @@ -0,0 +1,51 @@ +/* + * Copyright 2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.stream.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Bean; +import org.springframework.retry.support.RetryTemplate; + +/** + * Marker to tag an instance of {@link RetryTemplate} to be used by the binder. + * This annotation is also a @Bean to simplify configuration (see below) + * + *
+ * @StreamRetryTemplate
+ * public RetryTemplate myRetryTemplate() {
+ *    return new RetryTemplate();
+ * }
+ * 
+ * + * @author Oleg Zhurakousky + * @since 2.1 + */ + +@Target({ElementType.FIELD,ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Bean +@Qualifier +public @interface StreamRetryTemplate { + +} diff --git a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binder/AbstractBinder.java b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binder/AbstractBinder.java index c3991fc51..e4fd06db8 100644 --- a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binder/AbstractBinder.java +++ b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binder/AbstractBinder.java @@ -23,6 +23,7 @@ import org.springframework.beans.BeansException; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.cloud.stream.annotation.StreamRetryTemplate; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.context.support.AbstractApplicationContext; @@ -64,7 +65,8 @@ public abstract class AbstractBinder