investigate async http client integration
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.8k
- Forks
- 1.9k
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 41
Description
Per 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;
}
}
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the Client interface and tracing how its existing synchronous execute method is used. Compare that contract with the callback model described for async HTTP clients, including error and completion handling. Done means a concrete compatibility approach is agreed, with the affected implementation points and tests identified; the issue names no files or tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100