OpenFeign / feign

Feign makes writing java http clients easier
Apache License 2.0
9.44k stars 1.92k forks source link

AsyncApacheHttp5Client : Proposal to make creating the callback FutureCallback<SimpleHttpResponse>> through a public factory method #2439

Open predatoralpha opened 4 months ago

predatoralpha commented 4 months ago

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>

kdavisk6 commented 3 weeks ago

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.