Class HttpClients
HttpClient
(and other API variations) instances.-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionCreates aMultiAddressHttpClientBuilder
for clients capable of parsing an absolute-form URL, connecting to multiple addresses with defaultLoadBalancer
and DNSServiceDiscoverer
usingbackground
discovery strategy.forMultiAddressUrl
(ServiceDiscoverer<HostAndPort, InetSocketAddress, ServiceDiscovererEvent<InetSocketAddress>> serviceDiscoverer) Deprecated.Creates aMultiAddressHttpClientBuilder
for clients capable of parsing an absolute-form URL, connecting to multiple addresses with defaultLoadBalancer
and DNSServiceDiscoverer
usingbackground
discovery strategy.forMultiAddressUrl
(String id, ServiceDiscoverer<HostAndPort, InetSocketAddress, ServiceDiscovererEvent<InetSocketAddress>> serviceDiscoverer, HttpClients.DiscoveryStrategy discoveryStrategy) Creates aMultiAddressHttpClientBuilder
for clients capable of parsing an absolute-form URL, connecting to multiple addresses with defaultLoadBalancer
, using the specifiedServiceDiscoverer
andHttpClients.DiscoveryStrategy
.forMultiAddressUrl
(String id, HttpClients.DiscoveryStrategy discoveryStrategy) Creates aMultiAddressHttpClientBuilder
for clients capable of parsing an absolute-form URL, connecting to multiple addresses with defaultLoadBalancer
and DNSServiceDiscoverer
using the specifiedHttpClients.DiscoveryStrategy
.static <U,
R> PartitionedHttpClientBuilder<U, R> forPartitionedAddress
(ServiceDiscoverer<U, R, PartitionedServiceDiscovererEvent<R>> serviceDiscoverer, U address, Function<HttpRequestMetaData, PartitionAttributesBuilder> partitionAttributesBuilderFactory) Deprecated.We are unaware of anyone using "partition" feature and plan to remove it in future releases.forResolvedAddress
(HostAndPort address) Creates aSingleAddressHttpClientBuilder
for an address with defaultLoadBalancer
.forResolvedAddress
(String host, int port) Creates aSingleAddressHttpClientBuilder
for a resolved address with defaultLoadBalancer
.static <R extends SocketAddress>
SingleAddressHttpClientBuilder<R,R> forResolvedAddress
(R address) Creates aSingleAddressHttpClientBuilder
for an address with defaultLoadBalancer
.forServiceAddress
(String serviceName) Creates aSingleAddressHttpClientBuilder
for the passedserviceName
with defaultLoadBalancer
and a DNSServiceDiscoverer
using SRV record lookups withbackground
discovery strategy.static <U,
R> SingleAddressHttpClientBuilder<U, R> forSingleAddress
(ServiceDiscoverer<U, R, ? extends ServiceDiscovererEvent<R>> serviceDiscoverer, U address) Creates aSingleAddressHttpClientBuilder
for a custom address type with defaultLoadBalancer
and user providedServiceDiscoverer
usingbackground
discovery strategy.static <U,
R> SingleAddressHttpClientBuilder<U, R> forSingleAddress
(ServiceDiscoverer<U, R, ? extends ServiceDiscovererEvent<R>> serviceDiscoverer, U address, HttpClients.DiscoveryStrategy discoveryStrategy) Creates aSingleAddressHttpClientBuilder
for a custom address type with defaultLoadBalancer
and user providedServiceDiscoverer
using the specifiedHttpClients.DiscoveryStrategy
.forSingleAddress
(HostAndPort address) Creates aSingleAddressHttpClientBuilder
for an address with defaultLoadBalancer
and DNSServiceDiscoverer
usingbackground
discovery strategy.forSingleAddress
(HostAndPort address, HttpClients.DiscoveryStrategy discoveryStrategy) Creates aSingleAddressHttpClientBuilder
for an address with defaultLoadBalancer
and DNSServiceDiscoverer
using the specifiedHttpClients.DiscoveryStrategy
.forSingleAddress
(String host, int port) Creates aSingleAddressHttpClientBuilder
for an address with defaultLoadBalancer
and DNSServiceDiscoverer
usingbackground
discovery strategy.forSingleAddress
(String host, int port, HttpClients.DiscoveryStrategy discoveryStrategy) Creates aSingleAddressHttpClientBuilder
for an address with defaultLoadBalancer
and DNSServiceDiscoverer
using the specifiedHttpClients.DiscoveryStrategy
.
-
Method Details
-
forMultiAddressUrl
Creates aMultiAddressHttpClientBuilder
for clients capable of parsing an absolute-form URL, connecting to multiple addresses with defaultLoadBalancer
and DNSServiceDiscoverer
usingbackground
discovery strategy.When a relative URL is passed in the
StreamingHttpRequest.requestTarget(String)
this client requires aHttpHeaderNames.HOST
present in order to infer the remote address.The returned builder can be customized using
HttpProviders.MultiAddressHttpClientBuilderProvider
.- Returns:
- new builder with default configuration
- See Also:
-
forMultiAddressUrl
public static MultiAddressHttpClientBuilder<HostAndPort,InetSocketAddress> forMultiAddressUrl(String id) Creates aMultiAddressHttpClientBuilder
for clients capable of parsing an absolute-form URL, connecting to multiple addresses with defaultLoadBalancer
and DNSServiceDiscoverer
usingbackground
discovery strategy.When a relative URL is passed in the
StreamingHttpRequest.requestTarget(String)
this client requires aHttpHeaderNames.HOST
present in order to infer the remote address.The returned builder can be customized using
HttpProviders.MultiAddressHttpClientBuilderProvider
.- Parameters:
id
- a (unique) ID to identify the createdMultiAddressHttpClientBuilder
, like a name or a purpose of the future client that will be built. This helpsHttpProviders.MultiAddressHttpClientBuilderProvider
to distinguish this builder from others.- Returns:
- new builder with default configuration
- See Also:
-
forMultiAddressUrl
public static MultiAddressHttpClientBuilder<HostAndPort,InetSocketAddress> forMultiAddressUrl(String id, HttpClients.DiscoveryStrategy discoveryStrategy) Creates aMultiAddressHttpClientBuilder
for clients capable of parsing an absolute-form URL, connecting to multiple addresses with defaultLoadBalancer
and DNSServiceDiscoverer
using the specifiedHttpClients.DiscoveryStrategy
.When a relative URL is passed in the
StreamingHttpRequest.requestTarget(String)
this client requires aHttpHeaderNames.HOST
present in order to infer the remote address.The returned builder can be customized using
HttpProviders.MultiAddressHttpClientBuilderProvider
.- Parameters:
id
- a (unique) ID to identify the createdMultiAddressHttpClientBuilder
, like a name or a purpose of the future client that will be built. This helpsHttpProviders.MultiAddressHttpClientBuilderProvider
to distinguish this builder from others.discoveryStrategy
-HttpClients.DiscoveryStrategy
to use- Returns:
- new builder with default configuration
- See Also:
-
forMultiAddressUrl
public static MultiAddressHttpClientBuilder<HostAndPort,InetSocketAddress> forMultiAddressUrl(String id, ServiceDiscoverer<HostAndPort, InetSocketAddress, ServiceDiscovererEvent<InetSocketAddress>> serviceDiscoverer, HttpClients.DiscoveryStrategy discoveryStrategy) Creates aMultiAddressHttpClientBuilder
for clients capable of parsing an absolute-form URL, connecting to multiple addresses with defaultLoadBalancer
, using the specifiedServiceDiscoverer
andHttpClients.DiscoveryStrategy
.When a relative URL is passed in the
StreamingHttpRequest.requestTarget(String)
this client requires aHttpHeaderNames.HOST
present in order to infer the remote address.The returned builder can be customized using
HttpProviders.MultiAddressHttpClientBuilderProvider
.- Parameters:
id
- a (unique) ID to identify the createdMultiAddressHttpClientBuilder
, like a name or a purpose of the future client that will be built. This helpsHttpProviders.MultiAddressHttpClientBuilderProvider
to distinguish this builder from others.serviceDiscoverer
- TheServiceDiscoverer
to resolve addresses of remote servers to connect to. The lifecycle of the providedServiceDiscoverer
should be managed by the caller.discoveryStrategy
-HttpClients.DiscoveryStrategy
to use.- Returns:
- new builder with default configuration.
- See Also:
-
forMultiAddressUrl
@Deprecated public static MultiAddressHttpClientBuilder<HostAndPort,InetSocketAddress> forMultiAddressUrl(ServiceDiscoverer<HostAndPort, InetSocketAddress, ServiceDiscovererEvent<InetSocketAddress>> serviceDiscoverer) Deprecated.UseforMultiAddressUrl()
to createMultiAddressHttpClientBuilder
, then useMultiAddressHttpClientBuilder.initializer(SingleAddressInitializer)
to overrideServiceDiscoverer
usingSingleAddressHttpClientBuilder.serviceDiscoverer(ServiceDiscoverer)
for all or some of the internal clients.Creates aMultiAddressHttpClientBuilder
for clients capable of parsing an absolute-form URL, connecting to multiple addresses with defaultLoadBalancer
and user providedServiceDiscoverer
.When a relative URL is passed in the
StreamingHttpRequest.requestTarget(String)
this client requires aHttpHeaderNames.HOST
present in order to infer the remote address.The returned builder can be customized using
HttpProviders.MultiAddressHttpClientBuilderProvider
.- Parameters:
serviceDiscoverer
- TheServiceDiscoverer
to resolve addresses of remote servers to connect to. The lifecycle of the providedServiceDiscoverer
should be managed by the caller.- Returns:
- new builder with default configuration
- See Also:
-
forSingleAddress
public static SingleAddressHttpClientBuilder<HostAndPort,InetSocketAddress> forSingleAddress(String host, int port) Creates aSingleAddressHttpClientBuilder
for an address with defaultLoadBalancer
and DNSServiceDiscoverer
usingbackground
discovery strategy.The returned builder can be customized using
HttpProviders.SingleAddressHttpClientBuilderProvider
.- Parameters:
host
- host to connect to, resolved by default using a DNSServiceDiscoverer
. This will also be used for theHttpHeaderNames.HOST
together with theport
. UseSingleAddressHttpClientBuilder.unresolvedAddressToHost(Function)
if you want to override that value orSingleAddressHttpClientBuilder.hostHeaderFallback(boolean)
if you want to disable this behavior.port
- port to connect to- Returns:
- new builder for the address
- See Also:
-
forSingleAddress
public static SingleAddressHttpClientBuilder<HostAndPort,InetSocketAddress> forSingleAddress(HostAndPort address) Creates aSingleAddressHttpClientBuilder
for an address with defaultLoadBalancer
and DNSServiceDiscoverer
usingbackground
discovery strategy.The returned builder can be customized using
HttpProviders.SingleAddressHttpClientBuilderProvider
.- Parameters:
address
- theUnresolvedAddress
to connect to, resolved by default using a DNSServiceDiscoverer
. This address will also be used for theHttpHeaderNames.HOST
. UseSingleAddressHttpClientBuilder.unresolvedAddressToHost(Function)
if you want to override that value orSingleAddressHttpClientBuilder.hostHeaderFallback(boolean)
if you want to disable this behavior.- Returns:
- new builder for the address
- See Also:
-
forSingleAddress
public static SingleAddressHttpClientBuilder<HostAndPort,InetSocketAddress> forSingleAddress(String host, int port, HttpClients.DiscoveryStrategy discoveryStrategy) Creates aSingleAddressHttpClientBuilder
for an address with defaultLoadBalancer
and DNSServiceDiscoverer
using the specifiedHttpClients.DiscoveryStrategy
.The returned builder can be customized using
HttpProviders.SingleAddressHttpClientBuilderProvider
.- Parameters:
host
- host to connect to, resolved by default using a DNSServiceDiscoverer
. This will also be used for theHttpHeaderNames.HOST
together with theport
. UseSingleAddressHttpClientBuilder.unresolvedAddressToHost(Function)
if you want to override that value orSingleAddressHttpClientBuilder.hostHeaderFallback(boolean)
if you want to disable this behavior.port
- port to connect todiscoveryStrategy
-HttpClients.DiscoveryStrategy
to use- Returns:
- new builder for the address
- See Also:
-
forSingleAddress
public static SingleAddressHttpClientBuilder<HostAndPort,InetSocketAddress> forSingleAddress(HostAndPort address, HttpClients.DiscoveryStrategy discoveryStrategy) Creates aSingleAddressHttpClientBuilder
for an address with defaultLoadBalancer
and DNSServiceDiscoverer
using the specifiedHttpClients.DiscoveryStrategy
.The returned builder can be customized using
HttpProviders.SingleAddressHttpClientBuilderProvider
.- Parameters:
address
- theUnresolvedAddress
to connect to, resolved by default using a DNSServiceDiscoverer
. This address will also be used for theHttpHeaderNames.HOST
. UseSingleAddressHttpClientBuilder.unresolvedAddressToHost(Function)
if you want to override that value orSingleAddressHttpClientBuilder.hostHeaderFallback(boolean)
if you want to disable this behavior.discoveryStrategy
-HttpClients.DiscoveryStrategy
to use- Returns:
- new builder for the address
- See Also:
-
forServiceAddress
public static SingleAddressHttpClientBuilder<String,InetSocketAddress> forServiceAddress(String serviceName) Creates aSingleAddressHttpClientBuilder
for the passedserviceName
with defaultLoadBalancer
and a DNSServiceDiscoverer
using SRV record lookups withbackground
discovery strategy.The returned builder can be customized using
HttpProviders.SingleAddressHttpClientBuilderProvider
.- Parameters:
serviceName
- The service name to resolve with SRV DNS.- Returns:
- new builder for the address
- See Also:
-
forResolvedAddress
public static SingleAddressHttpClientBuilder<HostAndPort,InetSocketAddress> forResolvedAddress(String host, int port) Creates aSingleAddressHttpClientBuilder
for a resolved address with defaultLoadBalancer
.- Parameters:
host
- resolved host address to connect. This will also be used for theHttpHeaderNames.HOST
together with theport
. UseSingleAddressHttpClientBuilder.unresolvedAddressToHost(Function)
if you want to override that value orSingleAddressHttpClientBuilder.hostHeaderFallback(boolean)
if you want to disable this behavior.Note, if
a proxy
is configured for this client, the proxy address also needs to be already resolved. Otherwise, runtime exceptions will be thrown when the client is built.The returned builder can be customized using
HttpProviders.SingleAddressHttpClientBuilderProvider
.port
- port to connect to- Returns:
- new builder for the address
- See Also:
-
forResolvedAddress
public static SingleAddressHttpClientBuilder<HostAndPort,InetSocketAddress> forResolvedAddress(HostAndPort address) Creates aSingleAddressHttpClientBuilder
for an address with defaultLoadBalancer
.- Parameters:
address
- theResolvedAddress
to connect. This address will also be used for theHttpHeaderNames.HOST
. UseSingleAddressHttpClientBuilder.unresolvedAddressToHost(Function)
if you want to override that value orSingleAddressHttpClientBuilder.hostHeaderFallback(boolean)
if you want to disable this behavior.Note, if
a proxy
is configured for this client, the proxy address also needs to be already resolved. Otherwise, runtime exceptions will be thrown when the client is built.The returned builder can be customized using
HttpProviders.SingleAddressHttpClientBuilderProvider
.- Returns:
- new builder for the address
- See Also:
-
forResolvedAddress
public static <R extends SocketAddress> SingleAddressHttpClientBuilder<R,R> forResolvedAddress(R address) Creates aSingleAddressHttpClientBuilder
for an address with defaultLoadBalancer
.The returned builder can be customized using
HttpProviders.SingleAddressHttpClientBuilderProvider
.- Type Parameters:
R
- The type of resolvedSocketAddress
.- Parameters:
address
- theResolvedAddress
to connect. This address will also be used for theHttpHeaderNames.HOST
. UseSingleAddressHttpClientBuilder.unresolvedAddressToHost(Function)
if you want to override that value orSingleAddressHttpClientBuilder.hostHeaderFallback(boolean)
if you want to disable this behavior.- Returns:
- new builder for the address
- See Also:
-
forSingleAddress
public static <U,R> SingleAddressHttpClientBuilder<U,R> forSingleAddress(ServiceDiscoverer<U, R, ? extends ServiceDiscovererEvent<R>> serviceDiscoverer, U address) Creates aSingleAddressHttpClientBuilder
for a custom address type with defaultLoadBalancer
and user providedServiceDiscoverer
usingbackground
discovery strategy.The returned builder can be customized using
HttpProviders.SingleAddressHttpClientBuilderProvider
.- Type Parameters:
U
- the type of address before resolution (unresolved address)R
- the type of address after resolution (resolved address)- Parameters:
serviceDiscoverer
- TheServiceDiscoverer
to resolve addresses of remote servers to connect to. The lifecycle of the providedServiceDiscoverer
should be managed by the caller.address
- theUnresolvedAddress
to connect to resolved using the providedserviceDiscoverer
. This address will also be used for theHttpHeaderNames.HOST
using a best effort conversion. UseSingleAddressHttpClientBuilder.unresolvedAddressToHost(Function)
if you want to override that value orSingleAddressHttpClientBuilder.hostHeaderFallback(boolean)
if you want to disable this behavior.- Returns:
- new builder with provided configuration
- See Also:
-
forSingleAddress
public static <U,R> SingleAddressHttpClientBuilder<U,R> forSingleAddress(ServiceDiscoverer<U, R, ? extends ServiceDiscovererEvent<R>> serviceDiscoverer, U address, HttpClients.DiscoveryStrategy discoveryStrategy) Creates aSingleAddressHttpClientBuilder
for a custom address type with defaultLoadBalancer
and user providedServiceDiscoverer
using the specifiedHttpClients.DiscoveryStrategy
.The returned builder can be customized using
HttpProviders.SingleAddressHttpClientBuilderProvider
.- Type Parameters:
U
- the type of address before resolution (unresolved address)R
- the type of address after resolution (resolved address)- Parameters:
serviceDiscoverer
- TheServiceDiscoverer
to resolve addresses of remote servers to connect to. The lifecycle of the providedServiceDiscoverer
should be managed by the caller.address
- theUnresolvedAddress
to connect to resolved using the providedserviceDiscoverer
. This address will also be used for theHttpHeaderNames.HOST
using a best effort conversion. UseSingleAddressHttpClientBuilder.unresolvedAddressToHost(Function)
if you want to override that value orSingleAddressHttpClientBuilder.hostHeaderFallback(boolean)
if you want to disable this behavior.discoveryStrategy
-HttpClients.DiscoveryStrategy
to use- Returns:
- new builder with provided configuration
- See Also:
-
forPartitionedAddress
@Deprecated public static <U,R> PartitionedHttpClientBuilder<U,R> forPartitionedAddress(ServiceDiscoverer<U, R, PartitionedServiceDiscovererEvent<R>> serviceDiscoverer, U address, Function<HttpRequestMetaData, PartitionAttributesBuilder> partitionAttributesBuilderFactory) Deprecated.We are unaware of anyone using "partition" feature and plan to remove it in future releases. If you depend on it, consider usingClientGroup
as an alternative or reach out to the maintainers describing the use-case.Creates aPartitionedHttpClientBuilder
for a custom address type with defaultLoadBalancer
and user providedServiceDiscoverer
.- Type Parameters:
U
- the type of address before resolution (unresolved address)R
- the type of address after resolution (resolved address)- Parameters:
serviceDiscoverer
- TheServiceDiscoverer
to resolve addresses of remote servers to connect to. The lifecycle of the providedServiceDiscoverer
should be managed by the caller.address
- theUnresolvedAddress
to resolve using the providedserviceDiscoverer
. This address will also be used for theHttpHeaderNames.HOST
using a best effort conversion. UsePartitionedHttpClientBuilder.initializer(PartitionedHttpClientBuilder.SingleAddressInitializer)
andSingleAddressHttpClientBuilder.unresolvedAddressToHost(Function)
if you want to override that value orSingleAddressHttpClientBuilder.hostHeaderFallback(boolean)
if you want to disable this behavior.partitionAttributesBuilderFactory
- The factoryFunction
used to buildPartitionAttributes
fromHttpRequestMetaData
.- Returns:
- new builder with provided configuration
-
forMultiAddressUrl()
to createMultiAddressHttpClientBuilder
, then useMultiAddressHttpClientBuilder.initializer(SingleAddressInitializer)
to overrideServiceDiscoverer
usingSingleAddressHttpClientBuilder.serviceDiscoverer(ServiceDiscoverer)
for all or some of the internal clients.