Pass Threadlocal across "@Bulkhead" annotation
See original GitHub issueHi team,
We are trying to migrate from Hystrix to Resiliency4j. We have context value set in ThreadLocal. Whenever we go across @Bulkhead
annotation the ThreadLocal is empty
@Bulkhead(name = "backendA", type = Type.THREADPOOL)
public CompletableFuture<String> futureSuccessReqCtx() {
//empty thread local here
}
In Hystrix we were copying thread local using HystrixConcurrencyStrategy
. Do we have anything equivalent in Resiliency4j. If not, please suggest any other approach.
Issue Analytics
- State:
- Created 4 years ago
- Comments:29 (20 by maintainers)
Top Results From Across the Web
Implementing Bulkhead with Resilience4j - Reflectoring
Sometimes we store data in a ThreadLocal variable and read it in a different area of the code. We do this to avoid...
Read more >java - ThreadLocal value access across different threads
currentThread() , but you can pass in other threads if you wish. However, this likely isn't a great idea. For one, holding a...
Read more >Home of Quarkus Cheat-Sheet - GitHub Pages
When a request cannot be processed BulkheadException is thrown. It can be used together with any other fault tolerance annotation. @Bulkhead(5) @Retry ...
Read more >Rest Client for MicroProfile
This simple API exposes one API call, located at /greet from the base URL of the client. Invoking this endpoint returns a javax.ws.rs.core....
Read more >An Introduction to ThreadLocal in Java - Baeldung
In this tutorial, we'll be looking at the ThreadLocal construct from the java.lang package. This gives us the ability to store data ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @RobWin,
I actually found a way to pass context to the threads without touching the lib:
This can obviously be extended to pass more context to the executing thread.
Given that we can achieve this result without messing with Resilience4j, I’m now wondering how useful it would be to add such a feature directly in the lib. But if you think it’s still a good idea, it could work this way:
Developers can register
ContextPropagator
s via the BulkheadConfig. AContextPropagator
provides 3 things:Or translated in code:
Then in the implementation of
FixedThreadPoolBulkhead::submit
, I would change it to something like that:This is just a rough idea on how this would work. If that’s interesting, the API must be worked on carefully, as the config now provides hooks and is no longer a value store.
Thats correct. We need to improve the documentation. Currently the best documentation is our test:
https://github.com/resilience4j/resilience4j/blob/master/resilience4j-spring-boot2/src/test/resources/application.yaml#L163-L164
https://github.com/resilience4j/resilience4j/blob/master/resilience4j-spring-boot2/src/test/java/io/github/resilience4j/TestThreadLocalContextPropagator.java