RxNetty icon indicating copy to clipboard operation
RxNetty copied to clipboard

Create Http Client without binding it to an endpoint

Open moderakh opened this issue 8 years ago • 3 comments

Hi,

We are on RxNetty 0.4.x. Seems passing endpoint to RxNetty.createHttpClient(.) is required. https://github.com/ReactiveX/RxNetty/blob/0.4.x/rxnetty/src/main/java/io/reactivex/netty/RxNetty.java#L169-L170

I wonder how we should instantiate an http client using rxnetty without binding it to a specific endpoint at the instantiation time? (The use case is for fail over scenarios from one endpoint to other endpoint known at runtime)

Other http clients (e.g., apache http client) allow instantiating a client without binding it to a specific endpoint at the instantiation time, but not sure how to do it using rxnetty

Thanks

moderakh avatar Feb 12 '18 17:02 moderakh

No good answer on why. My only advise would be to create a factory method/object to hide this away.

I think this should be another candidate for review in 1.0.x

jamesgorman2 avatar Feb 13 '18 19:02 jamesgorman2

@jamesgorman2 wouldn't https://github.com/ReactiveX/RxNetty/blob/0.4.x/rxnetty/src/main/java/io/reactivex/netty/protocol/http/client/CompositeHttpClient.java work for this purpose?

I found this in the documentation:

/**
 * An implementation of {@link HttpClient} that can execute requests over multiple hosts.
 * Internally this implementation uses one {@link HttpClientImpl} per unique
 * {@link io.reactivex.netty.client.RxClient.ServerInfo}.
 * The only way to create this client is via the {@link CompositeHttpClientBuilder}
 *
 * @author Nitesh Kant
 */
public class CompositeHttpClient<I, O> extends HttpClientImpl<I, O> {

moderakh avatar Feb 13 '18 20:02 moderakh

Just did a quick scan of the code and it looks like that will do what you want. This wasn't ported to 0.5.x so I missed it.

jamesgorman2 avatar Feb 14 '18 02:02 jamesgorman2