fix:fix retry loadbalancer not working bug. (#1155)

pull/1169/head
Haotian Zhang 1 year ago committed by GitHub
parent d1e4a74ac4
commit c7c0d1793b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -8,4 +8,5 @@
- [feat:support service contract reporting.](https://github.com/Tencent/spring-cloud-tencent/pull/1141)
- [feat: support log path configuration parameters,](https://github.com/Tencent/spring-cloud-tencent/pull/1142)
- [feat:add swagger report switch.](https://github.com/Tencent/spring-cloud-tencent/pull/1150)
- [fix: dynamic routing using cookies.](https://github.com/Tencent/spring-cloud-tencent/pull/1153)
- [fix: dynamic routing using cookies.](https://github.com/Tencent/spring-cloud-tencent/pull/1153)
- [fix:fix retry loadbalancer not working bug.](https://github.com/Tencent/spring-cloud-tencent/pull/1155)

@ -25,12 +25,12 @@ import com.tencent.cloud.rpc.enhancement.resttemplate.EnhancedRestTemplateInterc
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.ConditionalOnDiscoveryEnabled;
import org.springframework.cloud.client.loadbalancer.LoadBalancerInterceptor;
import org.springframework.cloud.client.loadbalancer.RestTemplateCustomizer;
import org.springframework.cloud.client.loadbalancer.RetryLoadBalancerInterceptor;
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClients;
import org.springframework.cloud.loadbalancer.config.LoadBalancerAutoConfiguration;
import org.springframework.context.annotation.Bean;
@ -52,19 +52,23 @@ import org.springframework.http.client.ClientHttpRequestInterceptor;
public class PolarisLoadBalancerAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public RestTemplateCustomizer restTemplateCustomizer(@Autowired(required = false) LoadBalancerInterceptor loadBalancerInterceptor) {
public RestTemplateCustomizer restTemplateCustomizer(
@Autowired(required = false) RetryLoadBalancerInterceptor retryLoadBalancerInterceptor,
@Autowired(required = false) LoadBalancerInterceptor loadBalancerInterceptor) {
return restTemplate -> {
List<ClientHttpRequestInterceptor> list = new ArrayList<>(restTemplate.getInterceptors());
// LoadBalancerInterceptor must invoke before EnhancedRestTemplateInterceptor
if (loadBalancerInterceptor != null) {
if (retryLoadBalancerInterceptor != null || loadBalancerInterceptor != null) {
int addIndex = list.size();
for (int i = 0; i < list.size(); i++) {
if (list.get(i) instanceof EnhancedRestTemplateInterceptor) {
addIndex = i;
}
}
list.add(addIndex, loadBalancerInterceptor);
list.add(addIndex,
retryLoadBalancerInterceptor != null
? retryLoadBalancerInterceptor
: loadBalancerInterceptor);
}
restTemplate.setInterceptors(list);
};

@ -29,6 +29,11 @@
<artifactId>spring-cloud-starter-tencent-polaris-contract</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.retry</groupId>-->
<!-- <artifactId>spring-retry</artifactId>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>com.tencent.polaris</groupId>-->
<!-- <artifactId>connector-consul</artifactId>-->

Loading…
Cancel
Save