-
Notifications
You must be signed in to change notification settings - Fork 2k
Open
Labels
enhancementFor recommending new capabilitiesFor recommending new capabilitiesfeign-12Issues that are related to the next major releaseIssues that are related to the next major releaseproposalProposed Specification or API changeProposed Specification or API change
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;
}
}
}
}destan, ollio, alexander-lukyanchikov-epam, maheshmahadevan, muaazsaleem and 3 more
Metadata
Metadata
Assignees
Labels
enhancementFor recommending new capabilitiesFor recommending new capabilitiesfeign-12Issues that are related to the next major releaseIssues that are related to the next major releaseproposalProposed Specification or API changeProposed Specification or API change