Hello,
I was faced with the problem to save thread-dependent data from the request-thread in an asynchronous httpclient-dispatch thread, for correctly output the necessary information in the Slf4jLogger logs, for example parentRequestId
The point of intersection of these threads is creation FutureCallback> - here thread-dependent information from request-thread can be stored in the callback for an asynchronous thread
I make workaround - I implemented this by proxying the class CloseableHttpAsyncClient and reflectively replacing the callback to its wrapper, with the necessary information from the request-thread to async
However, it would be convenient to have a public factory in the class with the ability to replace this factory to your own, for more convenient creation of a wrapper over a callback.
I suggest this code:
https://github.com/predatoralpha/AsyncApacheHttp5Client_proposal/blob/main/AsyncApacheHttp5Client.java
Here the factory is implemented via BiFunction<Request, CompletableFuture, FutureCallback>
Thank you for your proposal and it seems like a reasonable addition. I recommend creating a pull-request to get direct feedback on your implementation.
Hello, I was faced with the problem to save thread-dependent data from the request-thread in an asynchronous httpclient-dispatch thread, for correctly output the necessary information in the Slf4jLogger logs, for example parentRequestId The point of intersection of these threads is creation FutureCallback> - here thread-dependent information from request-thread can be stored in the callback for an asynchronous thread
I make workaround - I implemented this by proxying the class CloseableHttpAsyncClient and reflectively replacing the callback to its wrapper, with the necessary information from the request-thread to async
However, it would be convenient to have a public factory in the class with the ability to replace this factory to your own, for more convenient creation of a wrapper over a callback.
I suggest this code:
https://github.com/predatoralpha/AsyncApacheHttp5Client_proposal/blob/main/AsyncApacheHttp5Client.java
Here the factory is implemented via BiFunction<Request, CompletableFuture, FutureCallback>