investigate async http client integration
See original GitHub issuePer a discussion with @niteshkant, I believe we can make a compatible http response callback interface to facilitate nio support.
Context
Many async http clients provide a callback interface such as below
Future<Integer> f = asyncHttpClient.prepareGet("http://www.ning.com/").execute(
new AsyncCompletionHandler<Integer>(){
@Override
public Integer onCompleted(Response response) throws Exception{
// Do something with the Response
return response.getStatusCode();
}
@Override
public void onThrowable(Throwable t){
// Something wrong happened.
}
});
https://github.com/AsyncHttpClient/async-http-client
How
It should be possible to extend our Client
to be compatible with the callback system from one or more async http clients, avoiding the need to independently manage threads in Feign.
ex.
interface Client {
// existing
Response execute(Request request, Options options) throws IOException;
// new
void execute(Request request, Options options, IncrementalCallback<Response> responseCallback);
An asynchronous client would need to map their callback to ours.
Any synchronous http client (including our default) could extend from a base class that implements the callback method like so
void execute(Request request, Options options, IncrementalCallback<Response> responseCallback) {
httpExecutor.get().execute(new Runnable() {
@Override public void run() {
Error error = null;
try {
responseCallback.onNext(execute(request, options));
responseCallback.onSuccess();
} catch (Error cause) {
// assign to a variable in case .onFailure throws a RTE
error = cause;
responseCallback.onFailure(cause);
} catch (Throwable cause) {
responseCallback.onFailure(cause);
} finally {
Thread.currentThread().setName(IDLE_THREAD_NAME);
if (error != null)
throw error;
}
}
}
}
Issue Analytics
- State:
- Created 10 years ago
- Reactions:8
- Comments:13 (6 by maintainers)
Top Results From Across the Web
How To Know All Asynchronous HTTP Calls are Completed
The most simple way would be to keep a count of how many requests are 'in flight'. Increment it for each request enqueued,...
Read more >Asynchronous HTTP with async-http-client in Java - Baeldung
AsyncHttpClient (AHC) is a library build on top of Netty, with the purpose of easily executing HTTP requests and processing responses ...
Read more >Asynchronous Request-Reply pattern - Azure - Microsoft Learn
The API responds synchronously as quickly as possible. It returns an HTTP 202 (Accepted) status code, acknowledging that the request has been received...
Read more >Working with the HttpClient Class - Simple Talk
To simulate load, the code will iterate through this call ten times. At each iteration, it calls up the endpoint with a GET...
Read more >HTTP Client | IntelliJ IDEA Documentation - JetBrains
When you are developing an application that addresses a RESTful web service. In this case, it is helpful to investigate the access to...
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 Free
Top 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
Yeah I think we should have a separate topic for non-blocking vs async invocation. In my mind, I thought something like rxnetty could be a faster path towards this, since for example, the callbacks are built to work together with the non-blocking transport.
Significant surgery is needed regardless, as Feign’t client type is blocking. I’d rather special-case one combo (I think we talked about “stacks” before) vs design a base client which seems to be portable, but actually only works reasonably with one http transport and one invocation/composition model.
I see. Actually planning to use Hystrix w/ Rx. However what concerns me is the lack of non-blocking client support. Maybe I’m missing something, but it seems that Feign uses either Apache HttpClient or OkHttp - both in blocking mode? Was hoping that Async HttpClient would allow me to do non-blocking requests.