You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
Issue Summary:
I encountered an issue while using Spring Cloud OpenFeign. When configuring circuit breaking (resilience4j), the FeignCircuitBreakerInvocationHandler submits our Feign client to be processed by an asynchronous thread, resulting in the loss of ThreadLocal information in the request context. Do you have any suggestions for resolving this issue?
Business Scenario:
In a Spring Web project, we have a custom RequestInterceptor that retrieves information stored in ThreadLocal before making a request. This information is used to populate RequestHeader and is then passed to downstream services. However, after introducing resilience4j as a circuit breaker in OpenFeign, resilience4j executes requests in a thread pool, causing ThreadLocal information to be lost.
Describe the solution you'd like
Proposal:
Therefore, I propose adding a hook (template method) within the org.springframework.cloud.openfeign.FeignCircuitBreakerInvocationHandler#asSupplier method in OpenFeign. This hook would allow the application service to retrieve the ThreadLocal object and, within the Supplier, set the ThreadLocal to the executing thread's ThreadLocal, similar to how it is done with RequestContextHolder. Is this approach feasible?
Below is sample code, assuming SubjectContext is a hook
I have also considered using a hook provided by resilience4j during application startup, specifically within org.springframework.cloud.circuitbreaker.resilience4j.Resilience4JCircuitBreakerFactory#configureExecutorService. By passing a custom thread pool object here, I could potentially propagate the ThreadLocal information. Sample code is as follows:
However, I find it less elegant, and I believe resolving it within the asSupplier() method of OpenFeign would be more versatile and applicable to a broader range of scenarios.
Additional context spring-cloud-openfeign-3.1.2
The text was updated successfully, but these errors were encountered:
Hello @imyzt, thanks for reporting the issue. Spring Cloud OpenFeign is now under maintenance and we are not planning much active development, however, if a PR is submitted, we will review it.
Is your feature request related to a problem? Please describe.
Issue Summary:
I encountered an issue while using Spring Cloud OpenFeign. When configuring circuit breaking (resilience4j), the
FeignCircuitBreakerInvocationHandler
submits our Feign client to be processed by an asynchronous thread, resulting in the loss ofThreadLocal
information in the request context. Do you have any suggestions for resolving this issue?Business Scenario:
In a Spring Web project, we have a custom
RequestInterceptor
that retrieves information stored inThreadLocal
before making a request. This information is used to populateRequestHeader
and is then passed to downstream services. However, after introducing resilience4j as a circuit breaker in OpenFeign, resilience4j executes requests in a thread pool, causingThreadLocal
information to be lost.Describe the solution you'd like
Proposal:
Therefore, I propose adding a hook (template method) within the
org.springframework.cloud.openfeign.FeignCircuitBreakerInvocationHandler#asSupplier
method in OpenFeign. This hook would allow the application service to retrieve theThreadLocal
object and, within the Supplier, set theThreadLocal
to the executing thread'sThreadLocal
, similar to how it is done withRequestContextHolder
. Is this approach feasible?Below is sample code, assuming
SubjectContext
is a hookDescribe alternatives you've considered
I have also considered using a hook provided by resilience4j during application startup, specifically within
org.springframework.cloud.circuitbreaker.resilience4j.Resilience4JCircuitBreakerFactory#configureExecutorService
. By passing a custom thread pool object here, I could potentially propagate theThreadLocal
information. Sample code is as follows:However, I find it less elegant, and I believe resolving it within the
asSupplier()
method of OpenFeign would be more versatile and applicable to a broader range of scenarios.Additional context
spring-cloud-openfeign-3.1.2
The text was updated successfully, but these errors were encountered: