You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Micky Lee <mi...@cyberpowersystems.com.tw> on 2010/10/27 11:00:45 UTC
Is there any simple Asynchronous Http Client can use?
Hi,
I want an asynchronous http client, and I found the svn repository: http://svn.apache.org/repos/asf/httpcomponents/httpasyncclient/
I want a notify when the request has response with a callback function, but the AsyncHttpClient only has the API to do "awaitResponse ()" method to wait and block until there is response.
I think the using of it may not be called an asynchronous http client.
The test case in example org.apache.http.examples.nio.client. AsyncClientRequest is
----
...
HttpHost target = new HttpHost("www.google.ch", 80);
BasicHttpRequest request = new BasicHttpRequest("GET", "/");
HttpExchange[] httpx = new HttpExchange[10];
for (int i = 0; i < httpx.length; i++) {
httpx[i] = asynchttpclient.execute(target, request);
}
for (int i = 0; i < httpx.length; i++) {
HttpResponse response = httpx[i].awaitResponse(); // block here
if (response != null) {
System.out.println("Response: " + response.getStatusLine());
}
}
...
----
When I change the code to following, it blocks one by one and not the one I want, because I don't know which one will have response quickly.
----
...
HttpHost target = new HttpHost("www.google.ch", 80);
BasicHttpRequest request = new BasicHttpRequest("GET", "/");
HttpExchange[] httpx = new HttpExchange[10];
for (int i = 0; i < httpx.length; i++) {
httpx[i] = asynchttpclient.execute(target, request);
HttpResponse response = httpx[i].awaitResponse(); // block here
if (response != null) {
System.out.println("Response: " + response.getStatusLine());
}
}
...
----
Any suggestion is welcome, thanks in advance.
Sincerely,
Micky
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org
RE: Is there any simple Asynchronous Http Client can use?
Posted by Tatu Saloranta <co...@yahoo.com>.
For what it's worth, there is also this:
http://github.com/AsyncHttpClient
which is NIO-based asynchronous client, and it is being actively developed (devs from Sonatype and Ning fwiw).
-+ Tatu +-
--- On Wed, 10/27/10, Micky Lee <mi...@cyberpowersystems.com.tw> wrote:
> From: Micky Lee <mi...@cyberpowersystems.com.tw>
> Subject: RE: Is there any simple Asynchronous Http Client can use?
> To: "'HttpClient User Discussion'" <ht...@hc.apache.org>
> Date: Wednesday, October 27, 2010, 6:03 AM
> Dear Oleg,
>
> OK, thanks for your reply.
>
> I will try the Jetty HTTP client and hope to see one day
> the NIO Apache HttpClient will come out as stable release.
>
> Sincerely,
> Mciky
>
> -----Original Message-----
> From: Oleg Kalnichevski [mailto:olegk@apache.org]
>
> Sent: Wednesday, October 27, 2010 6:37 PM
> To: HttpClient User Discussion
> Subject: Re: Is there any simple Asynchronous Http Client
> can use?
>
>
> > Hi Micky
>
> > The async version of Apache HttpClient based on NIO is
> still in a very
> > early (pre-ALPHA) stage of development. Lots essential
> bits are still
> > missing including a callback mechanism for completed
> HTTP exchanges.
>
> > Please note there is nothing that prevents you from
> adding asynchronous
> > callbacks to the stock version of Apache HttpClient
> 4.x with a fairly
> > modest amount of custom code.
>
> > If you are absolutely sure you want a NIO based HTTP
> client, there is at
> > least a few available. I can recommend Jetty HTTP
> client.
>
> > Hope this helps
>
> > Oleg
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org
RE: Is there any simple Asynchronous Http Client can use?
Posted by Micky Lee <mi...@cyberpowersystems.com.tw>.
Dear Oleg,
OK, thanks for your reply.
I will try the Jetty HTTP client and hope to see one day the NIO Apache HttpClient will come out as stable release.
Sincerely,
Mciky
-----Original Message-----
From: Oleg Kalnichevski [mailto:olegk@apache.org]
Sent: Wednesday, October 27, 2010 6:37 PM
To: HttpClient User Discussion
Subject: Re: Is there any simple Asynchronous Http Client can use?
> Hi Micky
> The async version of Apache HttpClient based on NIO is still in a very
> early (pre-ALPHA) stage of development. Lots essential bits are still
> missing including a callback mechanism for completed HTTP exchanges.
> Please note there is nothing that prevents you from adding asynchronous
> callbacks to the stock version of Apache HttpClient 4.x with a fairly
> modest amount of custom code.
> If you are absolutely sure you want a NIO based HTTP client, there is at
> least a few available. I can recommend Jetty HTTP client.
> Hope this helps
> Oleg
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org
Re: Is there any simple Asynchronous Http Client can use?
Posted by Oleg Kalnichevski <ol...@apache.org>.
On Wed, 2010-10-27 at 17:00 +0800, Micky Lee wrote:
> Hi,
>
> I want an asynchronous http client, and I found the svn repository: http://svn.apache.org/repos/asf/httpcomponents/httpasyncclient/
>
> I want a notify when the request has response with a callback function, but the AsyncHttpClient only has the API to do "awaitResponse ()" method to wait and block until there is response.
>
> I think the using of it may not be called an asynchronous http client.
>
> The test case in example org.apache.http.examples.nio.client. AsyncClientRequest is
>
...
> Any suggestion is welcome, thanks in advance.
>
>
> Sincerely,
> Micky
>
Hi Micky
The async version of Apache HttpClient based on NIO is still in a very
early (pre-ALPHA) stage of development. Lots essential bits are still
missing including a callback mechanism for completed HTTP exchanges.
Please note there is nothing that prevents you from adding asynchronous
callbacks to the stock version of Apache HttpClient 4.x with a fairly
modest amount of custom code.
If you are absolutely sure you want a NIO based HTTP client, there is at
least a few available. I can recommend Jetty HTTP client.
Hope this helps
Oleg
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org