GH-1405 added RetryTemplate qualifier (#1406)
* GH-1405 added RetryTemplate qualifier Added @StreamRetryTemplate qualifier annotation Resolves #1405 * GH-1405 renamed field to >
This commit is contained in:
committed by
Gary Russell
parent
028245b703
commit
eea20befc3
@@ -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
|
||||
|
||||
@@ -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)
|
||||
*
|
||||
* <pre class="code">
|
||||
* @StreamRetryTemplate
|
||||
* public RetryTemplate myRetryTemplate() {
|
||||
* return new RetryTemplate();
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @author Oleg Zhurakousky
|
||||
* @since 2.1
|
||||
*/
|
||||
|
||||
@Target({ElementType.FIELD,ElementType.METHOD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Bean
|
||||
@Qualifier
|
||||
public @interface StreamRetryTemplate {
|
||||
|
||||
}
|
||||
@@ -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<T, C extends ConsumerProperties, P extends
|
||||
private volatile EvaluationContext evaluationContext;
|
||||
|
||||
@Autowired(required=false) // this would need to be refactored into constructor in the future
|
||||
private RetryTemplate retryTemplate;
|
||||
@StreamRetryTemplate
|
||||
private RetryTemplate consumerBindingRetryTemplate;
|
||||
|
||||
/**
|
||||
* For binder implementations that support a prefix, apply the prefix to the name.
|
||||
@@ -176,7 +178,7 @@ public abstract class AbstractBinder<T, C extends ConsumerProperties, P extends
|
||||
* @return The retry template
|
||||
*/
|
||||
protected RetryTemplate buildRetryTemplate(ConsumerProperties properties) {
|
||||
RetryTemplate rt = this.retryTemplate;
|
||||
RetryTemplate rt = this.consumerBindingRetryTemplate;
|
||||
if (rt == null) {
|
||||
rt = new RetryTemplate();
|
||||
SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy();
|
||||
|
||||
Reference in New Issue
Block a user