Jetty HTTPClient connection reuse

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Jetty HTTPClient connection reuse

Bruno Konik

Hello all,

 

I am using Jetty HttpClient to post messages to a messaging platform (Messenger). I am observing that sometimes when sending 2 messages one after the other (sent by the same thread just one after the other), the second message arrives on the messaging platform before the first.

I am using non-blocking method where ‘url’ is the same URL for both send:

 

Request request = httpClient.newRequest(url).method(HttpMethod.POST).content(..);

Request.send(new BufferingResponseListener(1024) {

                @Override

                public void onComplete(Result result) {…});

 

Is this behavior normal ? How could I be sure that the first connection created by the first send will be reused by the second send ?

If not possible, should I use a mechanism that would queue the requests and send them with the blocking method?

 

Thanks for your help.

 

Bruno

 


_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: Jetty HTTPClient connection reuse

Simone Bordet-3
Hi,

On Wed, Dec 12, 2018 at 5:13 PM Bruno Konik <[hidden email]> wrote:

>
> Hello all,
>
>
>
> I am using Jetty HttpClient to post messages to a messaging platform (Messenger). I am observing that sometimes when sending 2 messages one after the other (sent by the same thread just one after the other), the second message arrives on the messaging platform before the first.
>
> I am using non-blocking method where ‘url’ is the same URL for both send:
>
>
>
> Request request = httpClient.newRequest(url).method(HttpMethod.POST).content(..);
>
> Request.send(new BufferingResponseListener(1024) {
>
>                 @Override
>
>                 public void onComplete(Result result) {…});
>
>
>
> Is this behavior normal ?

It is possible, yes.
You have 2 TCP connections, the 2 requests are sent one per
connection, and on the server it may happen that the second connection
is processed before the first.

> How could I be sure that the first connection created by the first send will be reused by the second send ?

There are 2 ways:

1) Use directly connections (pseudo code):
Promise<Connection> p = ...;
httpClient.getDestination(...).newConnection(p);
Request r = client.newRequest(...);
p.get().send(r, new BufferingResponseListener...)

2) Configure HttpClient with setMaxConnectionsPerDestination(1).

> If not possible, should I use a mechanism that would queue the requests and send them with the blocking method?

If you don't want to use either solution above, then yes you need to
do it at the application level with queueing, because it is your
application that requires ordering and HttpClient cannot know what
ordering you want.
In some cases having the second request arriving before the first is
an important feature - not for your case though.

--
Simone Bordet
----
http://cometd.org
http://webtide.com
Developer advice, training, services and support
from the Jetty & CometD experts.
_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: Jetty HTTPClient connection reuse

Bruno Konik
Thank you very much Simone.

Bruno

> -----Message d'origine-----
> De : [hidden email] [mailto:[hidden email]] De
> la part de Simone Bordet
> Envoyé : mercredi 12 décembre 2018 17:53
> À : JETTY user mailing list <[hidden email]>
> Objet : Re: [jetty-users] Jetty HTTPClient connection reuse
>
> Hi,
>
> On Wed, Dec 12, 2018 at 5:13 PM Bruno Konik <[hidden email]>
> wrote:
> >
> > Hello all,
> >
> >
> >
> > I am using Jetty HttpClient to post messages to a messaging platform
> (Messenger). I am observing that sometimes when sending 2 messages one after
> the other (sent by the same thread just one after the other), the second message
> arrives on the messaging platform before the first.
> >
> > I am using non-blocking method where ‘url’ is the same URL for both send:
> >
> >
> >
> > Request request =
> > httpClient.newRequest(url).method(HttpMethod.POST).content(..);
> >
> > Request.send(new BufferingResponseListener(1024) {
> >
> >                 @Override
> >
> >                 public void onComplete(Result result) {…});
> >
> >
> >
> > Is this behavior normal ?
>
> It is possible, yes.
> You have 2 TCP connections, the 2 requests are sent one per connection, and on
> the server it may happen that the second connection is processed before the first.
>
> > How could I be sure that the first connection created by the first send will be
> reused by the second send ?
>
> There are 2 ways:
>
> 1) Use directly connections (pseudo code):
> Promise<Connection> p = ...;
> httpClient.getDestination(...).newConnection(p);
> Request r = client.newRequest(...);
> p.get().send(r, new BufferingResponseListener...)
>
> 2) Configure HttpClient with setMaxConnectionsPerDestination(1).
>
> > If not possible, should I use a mechanism that would queue the requests and
> send them with the blocking method?
>
> If you don't want to use either solution above, then yes you need to do it at the
> application level with queueing, because it is your application that requires
> ordering and HttpClient cannot know what ordering you want.
> In some cases having the second request arriving before the first is an important
> feature - not for your case though.
>
> --
> Simone Bordet
> ----
> http://cometd.org
> http://webtide.com
> Developer advice, training, services and support from the Jetty & CometD
> experts.
> _______________________________________________
> jetty-users mailing list
> [hidden email]
> To change your delivery options, retrieve your password, or unsubscribe from this
> list, visit https://www.eclipse.org/mailman/listinfo/jetty-users

_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/jetty-users