REST client message metadata that can be intercepted in ClientRequestFilter within&outside vertX bootstrap #46770
-
Hello, These clients can be of different types:
Following your previous inputs, we implemented this requirement using ContextLocals: this approach involves storing per-client metadata in ContextLocals before performing the client call. A ClientRequestFilter then retrieves the metadata from the ContextLocals, removes it, and populates the outgoing header value accordingly. However, this method does not apply when the bootstrap is not an inbound REST server request, such as in EDA-to-SOA applications where a Kafka-Stream processor makes a client call or in a batch application (a raw QuarkusMain app) that performs client calls. In these cases, the REST client execution is not executed from a duplicated Vert.x context, making the ContextLocals solution inapplicable. We are considering falling back to using a ThreadLocal in such cases, based on the assumption that outside a reactive bootstrap (e.g., quarkus-rest, quarkus-reactive-messaging) that initiates the flow performing the client call, the processing is always single-threaded. Do you have any feedback on this fallback mechanism, or do you have other suggestions for implementing this feature outside a Vert.x bootstrap? And, eventually long-term, do you foresee the possibility of enhancing the quarkus-rest-client API to provide a way to specify client metadata that could be intercepted programmatically in a ClientRequestFilter? Thank you in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 12 replies
-
/cc @cescoffier (rest-client), @geoand (rest-client) |
Beta Was this translation helpful? Give feedback.
-
Thanks for raising this!
|
Beta Was this translation helpful? Give feedback.
WebSocket Next is doing it too:
quarkus/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/runtime/ContextSupport.java
Line 83 in 67e69e7
Basically, you create a duplicated context and then do
context.executeBlocking(....)
If you need to stay on the same thread, you would need something like:
quarkus/extensions/virtual-threads/runtime/src/main/java/io/quarkus/virtual/threads/ContextPreservingExecutorService.java
Line 40 in 67e69e7