Skip to content

Fix circuit breaker Feign builder direct usage#1390

Open
hutiefang76 wants to merge 1 commit into
spring-cloud:mainfrom
hutiefang76:codex/openfeign-1210-circuitbreaker-builder
Open

Fix circuit breaker Feign builder direct usage#1390
hutiefang76 wants to merge 1 commit into
spring-cloud:mainfrom
hutiefang76:codex/openfeign-1210-circuitbreaker-builder

Conversation

@hutiefang76

Copy link
Copy Markdown

Fixes gh-1210.

When the circuit breaker Feign.Builder bean is used directly, it currently gets created without the CircuitBreakerFactory, group setting, or CircuitBreakerNameResolver that 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:

  • direct Feign.Builder bean configuration with circuit breaker enabled
  • fallback resolver behavior when no resolver bean is available
  • using the target name when feignClientName is not set

Tested with:

./mvnw -pl spring-cloud-openfeign-core -Dtest=FeignAutoConfigurationTests test

Signed-off-by: hutiefang <hutiefang@qq.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.Builder bean with CircuitBreakerFactory, group-enabled flag, and a resolver fallback when no CircuitBreakerNameResolver bean is present.
  • Update FeignCircuitBreakerInvocationHandler to use target.name() when feignClientName is 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.

Comment on lines +132 to +135
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)));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No CircuitBreakerNameResolver set in circuitBreakerFeignBuilder Bean

4 participants