-
Notifications
You must be signed in to change notification settings - Fork 833
Fix circuit breaker Feign builder direct usage #1390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
39d5fa2
193e977
e830579
1129178
ee9bbf8
8876ec3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /* | ||
| * Copyright 2013-present 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 | ||
| * | ||
| * https://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.openfeign; | ||
|
|
||
| import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
|
||
| /** | ||
| * Configuration properties for Feign circuit breaker support. | ||
| */ | ||
| @ConfigurationProperties("spring.cloud.openfeign.circuitbreaker") | ||
| public class FeignCircuitBreakerProperties { | ||
|
|
||
| private Group group = new Group(); | ||
|
|
||
| private AlphanumericIds alphanumericIds = new AlphanumericIds(); | ||
|
|
||
| public Group getGroup() { | ||
| return group; | ||
| } | ||
|
|
||
| public void setGroup(Group group) { | ||
| this.group = group; | ||
| } | ||
|
|
||
| public AlphanumericIds getAlphanumericIds() { | ||
| return alphanumericIds; | ||
| } | ||
|
|
||
| public void setAlphanumericIds(AlphanumericIds alphanumericIds) { | ||
| this.alphanumericIds = alphanumericIds; | ||
| } | ||
|
|
||
| public static class Group { | ||
|
|
||
| private boolean enabled; | ||
|
|
||
| public boolean isEnabled() { | ||
| return enabled; | ||
| } | ||
|
|
||
| public void setEnabled(boolean enabled) { | ||
| this.enabled = enabled; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| public static class AlphanumericIds { | ||
|
|
||
| private boolean enabled = true; | ||
|
|
||
| public boolean isEnabled() { | ||
| return enabled; | ||
| } | ||
|
|
||
| public void setEnabled(boolean enabled) { | ||
| this.enabled = enabled; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,8 @@ | |
| import org.springframework.boot.http.converter.autoconfigure.ClientHttpMessageConvertersCustomizer; | ||
| import org.springframework.cloud.client.circuitbreaker.CircuitBreaker; | ||
| import org.springframework.cloud.client.circuitbreaker.CircuitBreakerFactory; | ||
| import org.springframework.cloud.openfeign.FeignAutoConfiguration.CircuitBreakerPresentFeignTargeterConfiguration.AlphanumericCircuitBreakerNameResolver; | ||
| import org.springframework.cloud.openfeign.FeignAutoConfiguration.CircuitBreakerPresentFeignTargeterConfiguration.DefaultCircuitBreakerNameResolver; | ||
| import org.springframework.cloud.openfeign.clientconfig.FeignClientConfigurer; | ||
| import org.springframework.cloud.openfeign.support.AbstractFormWriter; | ||
| import org.springframework.cloud.openfeign.support.FeignEncoderProperties; | ||
|
|
@@ -244,12 +246,35 @@ public Feign.Builder defaultFeignBuilder(Retryer retryer) { | |
| return Feign.builder().retryer(retryer); | ||
| } | ||
|
|
||
| /** | ||
| * @deprecated in favor of | ||
| * {@link #circuitBreakerFeignBuilder(CircuitBreakerFactory, FeignCircuitBreakerProperties, ObjectProvider)}. | ||
| */ | ||
| @Deprecated | ||
| public Feign.Builder circuitBreakerFeignBuilder() { | ||
| return FeignCircuitBreaker.builder(); | ||
| } | ||
|
|
||
| @Bean | ||
| @Scope("prototype") | ||
| @ConditionalOnMissingBean | ||
| @ConditionalOnBean(CircuitBreakerFactory.class) | ||
| public Feign.Builder circuitBreakerFeignBuilder() { | ||
| return FeignCircuitBreaker.builder(); | ||
| public Feign.Builder circuitBreakerFeignBuilder(CircuitBreakerFactory circuitBreakerFactory, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove From the old method, add them here and then inject the beans you need instead of autowiring them
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved the bean and conditional annotations to the injected overload. The original no-argument builder method remains a public, unannotated API, while the managed overload receives the dependencies. FeignAutoConfigurationTests passes (12 tests). |
||
| FeignCircuitBreakerProperties circuitBreakerProperties, | ||
| ObjectProvider<CircuitBreakerNameResolver> circuitBreakerNameResolver) { | ||
| return FeignCircuitBreaker.builder() | ||
| .circuitBreakerFactory(circuitBreakerFactory) | ||
| .circuitBreakerGroupEnabled(circuitBreakerProperties.getGroup().isEnabled()) | ||
| .circuitBreakerNameResolver(circuitBreakerNameResolver | ||
| .getIfAvailable(() -> defaultCircuitBreakerNameResolver(circuitBreakerProperties))); | ||
| } | ||
|
|
||
| private CircuitBreakerNameResolver defaultCircuitBreakerNameResolver( | ||
| FeignCircuitBreakerProperties circuitBreakerProperties) { | ||
| if (circuitBreakerProperties.getAlphanumericIds().isEnabled()) { | ||
| return new AlphanumericCircuitBreakerNameResolver(); | ||
| } | ||
| return new DefaultCircuitBreakerNameResolver(); | ||
| } | ||
|
|
||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same overload pattern needs to be applied here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Applied the same overload pattern here: restored the public circuitBreakerFeignTargeter(CircuitBreakerFactory, boolean, CircuitBreakerNameResolver) API and added the property-injected @bean overload that delegates to it. Added a reflection-based compatibility test. FeignAutoConfigurationTests passes (12 tests).