Fix circuit breaker Feign builder direct usage#1390
Conversation
Signed-off-by: hutiefang <hutiefang@qq.com>
409c73a to
2163b3e
Compare
There was a problem hiding this comment.
Pull request overview
This pull request fixes gh-1210 by ensuring the circuit breaker Feign.Builder bean is fully configured (factory, group flag, and name resolver) when it is used directly, so it behaves consistently with the normal Feign client targeter path. It also makes circuit breaker name/group resolution work when the builder is used outside the named Feign client path by falling back to the Feign Target name.
Changes:
- Configure the circuit-breaker
Feign.Builderbean withCircuitBreakerFactory, group-enabled flag, and a resolver fallback when noCircuitBreakerNameResolverbean is present. - Update
FeignCircuitBreakerInvocationHandlerto usetarget.name()whenfeignClientNameis not set (for direct builder usage). - Add tests covering direct builder configuration and target-name fallback behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignAutoConfigurationTests.java | Adds tests for direct circuit breaker builder configuration and target-name fallback behavior. |
| spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientsConfiguration.java | Configures the circuit breaker Feign.Builder bean with factory/group/resolver (including a default resolver fallback). |
| spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignCircuitBreakerInvocationHandler.java | Falls back to target.name() when feignClientName is null for circuit/group naming. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| assertThat(builder).isInstanceOf(FeignCircuitBreaker.Builder.class) | ||
| .hasFieldOrPropertyWithValue("circuitBreakerFactory", circuitBreakerFactory) | ||
| .hasFieldOrProperty("circuitBreakerNameResolver"); | ||
| }); |
| .circuitBreakerFactory(circuitBreakerFactory) | ||
| .circuitBreakerGroupEnabled(circuitBreakerGroupEnabled) | ||
| .circuitBreakerNameResolver(circuitBreakerNameResolver | ||
| .getIfAvailable(() -> (feignClientName, target, method) -> Feign.configKey(target.type(), method))); |
There was a problem hiding this comment.
Technically I believe the fallback name resolver would be AlphanumericCircuitBreakerNameResolver by default if alphanumeric-ids.enabled has matchIfMissing = true. We should probably check that property and use the correct name resolver
Fixes gh-1210.
When the circuit breaker
Feign.Builderbean is used directly, it currently gets created without theCircuitBreakerFactory, group setting, orCircuitBreakerNameResolverthat the normal Feign client targeter path applies later. That makes the direct builder path fail at invocation time instead of behaving like the regular circuit breaker Feign client path.This change configures the circuit breaker builder bean with the available factory, group flag, and resolver. It also falls back to the Feign target name when the builder is used outside the named Feign client targeter path.
Tests added for:
Feign.Builderbean configuration with circuit breaker enabledfeignClientNameis not setTested with: