Interface SingleAddressHttpClientBuilder<U,R>
- Type Parameters:
U- the type of address before resolution (unresolved address)R- the type of address after resolution (resolved address)
- All Known Implementing Classes:
DefaultHttpLoadBalancerProvider.LoadBalancerIgnoringBuilder,DelegatingSingleAddressHttpClientBuilder
StreamingHttpClient instances which call a single server based on the provided unresolved
address.
It also provides a good set of default settings and configurations, which could be used by most users as-is or could be overridden to address specific use cases.
-
Method Summary
Modifier and TypeMethodDescriptionallowDropResponseTrailers(boolean allowDrop) Provide a hint if response trailers are allowed to be dropped.Appends the filter to the chain of filters used to decorate theHttpClientcreated by this builder.appendClientFilter(Predicate<StreamingHttpRequest> predicate, StreamingHttpClientFilterFactory factory) Appends the filter to the chain of filters used to decorate theHttpClientcreated by this builder, for every request that passes the providedPredicate.Appends the filter to the chain of filters used to decorate theConnectionFactoryused by this builder.Appends the filter to the chain of filters used to decorate theStreamingHttpConnectioncreated by this builder.appendConnectionFilter(Predicate<StreamingHttpRequest> predicate, StreamingHttpConnectionFilterFactory factory) Appends the filter to the chain of filters used to decorate theStreamingHttpConnectioncreated by this builder, for every request that passes the providedPredicate.bufferAllocator(BufferAllocator allocator) default HttpClientbuild()Builds a newHttpClient.default BlockingHttpClientCreates a newBlockingHttpClient.default BlockingStreamingHttpClientCreates a newBlockingStreamingHttpClient.Builds a newStreamingHttpClient.enableWireLogging(String loggerName, LogLevel logLevel, BooleanSupplier logUserData) Enables wire-logging for connections created by this builder.executionStrategy(HttpExecutionStrategy strategy) Sets theHttpExecutionStrategyto be used for client callbacks when executing client requests for all clients created from this builder.hostHeaderFallback(boolean enable) Configures automatically settingHostheaders by inferring from the address.inferPeerHost(boolean shouldInfer) Toggle inference of value to use instead ofClientSslConfig.peerHost()from client's address when peer host is not specified.inferPeerPort(boolean shouldInfer) Toggle inference of value to use instead ofClientSslConfig.peerPort()from client's address when peer port is not specified (equals-1).inferSniHostname(boolean shouldInfer) Toggle SNI hostname inference from client's address if not explicitly specified viasslConfig(ClientSslConfig).ioExecutor(IoExecutor ioExecutor) loadBalancerFactory(HttpLoadBalancerFactory<R> loadBalancerFactory) Sets aHttpLoadBalancerFactoryto createLoadBalancerinstances.protocols(HttpProtocolConfig... protocols) Configurations of various HTTP protocol versions.default SingleAddressHttpClientBuilder<U,R> proxyAddress(U proxyAddress) Deprecated.default SingleAddressHttpClientBuilder<U,R> proxyConfig(ProxyConfig<U> proxyConfig) Configures a proxy to serve as an intermediary for requests.retryServiceDiscoveryErrors(BiIntFunction<Throwable, ? extends Completable> retryStrategy) Sets a retry strategy to retry errors emitted byServiceDiscoverer.serviceDiscoverer(ServiceDiscoverer<U, R, ? extends ServiceDiscovererEvent<R>> serviceDiscoverer) Sets aServiceDiscovererto resolve addresses of remote servers to connect to.socketOption(SocketOption<T> option, T value) Adds aSocketOptionfor all connections created by this builder.sslConfig(ClientSslConfig sslConfig) Set the SSL/TLS configuration.default SingleAddressHttpClientBuilder<U,R> transportConfig(TransportConfig transportConfig) Set the transport configuration.unresolvedAddressToHost(Function<U, CharSequence> unresolvedAddressToHostFunction) Provides a means to convertSingleAddressHttpClientBuilderunresolved address type into aCharSequence.
-
Method Details
-
proxyAddress
Deprecated.Configures a proxy to serve as an intermediary for requests.If the client talks to a proxy over http (not https,
ClientSslConfigis NOT configured), it will rewrite the request-target to absolute-form, as specified by the RFC.For secure proxy tunnels (when
ClientSslConfigis configured) the tunnel is always initialized using HTTP/1.1 CONNECT request. The actual protocol will be negotiated via ALPN extension of TLS protocol, taking into account HTTP protocols configured viaprotocols(HttpProtocolConfig...)method. In case of any error duringCONNECTprocess,ProxyConnectExceptionorProxyConnectResponseExceptionwill be thrown when a request attempt is made through the constructed client instance.- Parameters:
proxyAddress- Unresolved address of the proxy. When used with a builder created for a resolved address,proxyAddressshould also be already resolved – otherwise runtime exceptions may occur.- Returns:
this.
-
proxyConfig
Configures a proxy to serve as an intermediary for requests.If the client talks to a proxy over http (not https,
ClientSslConfigis NOT configured), it will rewrite the request-target to absolute-form, as specified by the RFC.For secure proxy tunnels (when
ClientSslConfigis configured) the tunnel is always initialized using HTTP/1.1 CONNECT request. The actual protocol will be negotiated via ALPN extension of TLS protocol, taking into account HTTP protocols configured viaprotocols(HttpProtocolConfig...)method. In case of any error duringCONNECTprocess,ProxyConnectExceptionorProxyConnectResponseExceptionwill be thrown when a request attempt is made through the constructed client instance.- Parameters:
proxyConfig- Configuration for a proxy. When used with a builder created for a resolved address,ProxyConfig.address()must also be already resolved – otherwise runtime exceptions will occur.- Returns:
this.- See Also:
-
socketOption
Adds aSocketOptionfor all connections created by this builder.- Type Parameters:
T- the type of the value.- Parameters:
option- the option to apply.value- the value.- Returns:
this.- See Also:
-
enableWireLogging
SingleAddressHttpClientBuilder<U,R> enableWireLogging(String loggerName, LogLevel logLevel, BooleanSupplier logUserData) Enables wire-logging for connections created by this builder.- Parameters:
loggerName- The name of the logger to log wire events.logLevel- The level to log at.logUserData-trueto include user data (e.g. data, headers, etc.).falseto exclude user data and log only network events. This method is invoked for each data object allowing for dynamic behavior.- Returns:
this.
-
protocols
Configurations of various HTTP protocol versions.Note: the order of specified protocols will reflect on priorities for ALPN in case the connections use TLS.
- Parameters:
protocols-HttpProtocolConfigfor each protocol that should be supported.- Returns:
this.
-
hostHeaderFallback
Configures automatically settingHostheaders by inferring from the address.When
falseis passed, this setting disables the default filter such that noHostheader will be manipulated.- Parameters:
enable- Whether a default filter for inferring theHostheaders should be added.- Returns:
this- See Also:
-
allowDropResponseTrailers
Provide a hint if response trailers are allowed to be dropped. This hint maybe ignored if the transport can otherwise infer that trailers should be preserved. For example, if the response headers contain Trailer then this hint maybe ignored.- Parameters:
allowDrop-trueif response trailers are allowed to be dropped.- Returns:
this
-
appendConnectionFilter
SingleAddressHttpClientBuilder<U,R> appendConnectionFilter(StreamingHttpConnectionFilterFactory factory) Appends the filter to the chain of filters used to decorate theStreamingHttpConnectioncreated by this builder.Filtering allows you to wrap a
StreamingHttpConnectionand modify behavior during request/response processing Some potential candidates for filtering include logging, metrics, and decorating responses.The order of execution of these filters are in order of append. If 3 filters are added as follows:
builder.appendConnectionFilter(filter1).appendConnectionFilter(filter2).appendConnectionFilter(filter3)making a request to a connection wrapped by this filter chain the order of invocation of these filters will be:filter1 ⇒ filter2 ⇒ filter3 ⇒ connection- Parameters:
factory-StreamingHttpConnectionFilterFactoryto decorate aStreamingHttpConnectionfor the purpose of filtering.- Returns:
this
-
appendConnectionFilter
SingleAddressHttpClientBuilder<U,R> appendConnectionFilter(Predicate<StreamingHttpRequest> predicate, StreamingHttpConnectionFilterFactory factory) Appends the filter to the chain of filters used to decorate theStreamingHttpConnectioncreated by this builder, for every request that passes the providedPredicate.Filtering allows you to wrap a
StreamingHttpConnectionand modify behavior during request/response processing Some potential candidates for filtering include logging, metrics, and decorating responses.The order of execution of these filters are in order of append. If 3 filters are added as follows:
builder.appendConnectionFilter(filter1).appendConnectionFilter(filter2).appendConnectionFilter(filter3)making a request to a connection wrapped by this filter chain the order of invocation of these filters will be:filter1 ⇒ filter2 ⇒ filter3 ⇒ connectionWhen overriding this method, delegate to
superas it uses internal utilities to provide a consistent execution flow.- Parameters:
predicate- thePredicateto test if the filter must be applied.factory-StreamingHttpConnectionFilterFactoryto decorate aStreamingHttpConnectionfor the purpose of filtering.- Returns:
this
-
ioExecutor
-
executor
-
executionStrategy
Sets theHttpExecutionStrategyto be used for client callbacks when executing client requests for all clients created from this builder.Specifying an execution strategy affects the offloading used during execution of client requests:
- Unspecified or
HttpExecutionStrategies.defaultStrategy() - Execution of client requests will use a safe (non-blocking) execution strategy appropriate for the
client API used and the filters added. Blocking is always safe as all potentially blocking paths are
offloaded. Each client API variant (async/blocking streaming/aggregate) requires a specific execution
strategy to avoid blocking the event-loop and filters added via
appendClientFilter(StreamingHttpClientFilterFactory),appendConnectionFilter(StreamingHttpConnectionFilterFactory), orappendConnectionFactoryFilter(ConnectionFactoryFilter), etc. may also require offloading. The execution strategy for execution of client requests will be computed based on the client API in use andHttpExecutionStrategyInfluencer.requiredOffloads()of added the filters. HttpExecutionStrategies.offloadNone()(or deprecatedHttpExecutionStrategies.offloadNever())- No offloading will be used during execution of client requests regardless of the client API used or the influence of added filters. Filters and asynchronous callbacks must not ever block during the execution of client requests.
- A custom execution strategy (
HttpExecutionStrategies.customStrategyBuilder()) orHttpExecutionStrategies.offloadAll() - The specified execution strategy will be used for executing client requests rather than the client API's default safe strategy. Like with the default strategy, the actual execution strategy used is computed from the provided strategy and the execution strategies required by added filters. Filters and asynchronous callbacks MAY only block during the offloaded portions of the client request execution.
- Parameters:
strategy-HttpExecutionStrategyto use. If callbacks to the application code may block then those callbacks must request to be offloaded.- Returns:
this.- See Also:
- Unspecified or
-
bufferAllocator
-
appendConnectionFactoryFilter
SingleAddressHttpClientBuilder<U,R> appendConnectionFactoryFilter(ConnectionFactoryFilter<R, FilterableStreamingHttpConnection> factory) Appends the filter to the chain of filters used to decorate theConnectionFactoryused by this builder.Filtering allows you to wrap a
ConnectionFactoryand modify behavior ofConnectionFactory.newConnection(Object, ContextMap, TransportObserver). Some potential candidates for filtering include logging and metrics.The order of execution of these filters are in order of append. If 3 filters are added as follows:
builder .appendConnectionFactoryFilter(filter1) .appendConnectionFactoryFilter(filter2) .appendConnectionFactoryFilter(filter3)CallingConnectionFactorywrapped by this filter chain, the order of invocation of these filters will be:filter1 ⇒ filter2 ⇒ filter3 ⇒ original connection factory- Parameters:
factory-ConnectionFactoryFilterto use.- Returns:
this
-
appendClientFilter
Appends the filter to the chain of filters used to decorate theHttpClientcreated by this builder.Note this method will be used to decorate the result of
build()before it is returned to the user.The order of execution of these filters are in order of append. If 3 filters are added as follows:
builder.appendClientFilter(filter1).appendClientFilter(filter2).appendClientFilter(filter3)making a request to a client wrapped by this filter chain the order of invocation of these filters will be:filter1 ⇒ filter2 ⇒ filter3 ⇒ client- Parameters:
factory-StreamingHttpClientFilterFactoryto decorate aHttpClientfor the purpose of filtering.- Returns:
this
-
appendClientFilter
SingleAddressHttpClientBuilder<U,R> appendClientFilter(Predicate<StreamingHttpRequest> predicate, StreamingHttpClientFilterFactory factory) Appends the filter to the chain of filters used to decorate theHttpClientcreated by this builder, for every request that passes the providedPredicate.Note this method will be used to decorate the result of
build()before it is returned to the user.The order of execution of these filters are in order of append. If 3 filters are added as follows:
builder.appendClientFilter(filter1).appendClientFilter(filter2).appendClientFilter(filter3)making a request to a client wrapped by this filter chain the order of invocation of these filters will be:filter1 ⇒ filter2 ⇒ filter3 ⇒ client- Parameters:
predicate- thePredicateto test if the filter must be applied.factory-StreamingHttpClientFilterFactoryto decorate aHttpClientfor the purpose of filtering.- Returns:
this
-
unresolvedAddressToHost
SingleAddressHttpClientBuilder<U,R> unresolvedAddressToHost(Function<U, CharSequence> unresolvedAddressToHostFunction) Provides a means to convertSingleAddressHttpClientBuilderunresolved address type into aCharSequence. An example of where this maybe used is to convert theSingleAddressHttpClientBuilderto a default host header. It may also be used in the event of proxying.- Parameters:
unresolvedAddressToHostFunction- invoked to convert theSingleAddressHttpClientBuilderunresolved address type into aCharSequencesuitable for use in Host Header format.- Returns:
this
-
serviceDiscoverer
SingleAddressHttpClientBuilder<U,R> serviceDiscoverer(ServiceDiscoverer<U, R, ? extends ServiceDiscovererEvent<R>> serviceDiscoverer) Sets aServiceDiscovererto resolve addresses of remote servers to connect to.- Parameters:
serviceDiscoverer- TheServiceDiscovererto resolve addresses of remote servers to connect to. Lifecycle of the providedServiceDiscovereris managed externally and it should beclosedafter all builtStreamingHttpClients will be closed and thisServiceDiscovereris no longer needed.- Returns:
this.
-
retryServiceDiscoveryErrors
SingleAddressHttpClientBuilder<U,R> retryServiceDiscoveryErrors(BiIntFunction<Throwable, ? extends Completable> retryStrategy) Sets a retry strategy to retry errors emitted byServiceDiscoverer.- Parameters:
retryStrategy- a retry strategy to retry errors emitted byServiceDiscoverer.- Returns:
this.- See Also:
-
loadBalancerFactory
SingleAddressHttpClientBuilder<U,R> loadBalancerFactory(HttpLoadBalancerFactory<R> loadBalancerFactory) Sets aHttpLoadBalancerFactoryto createLoadBalancerinstances.- Parameters:
loadBalancerFactory-HttpLoadBalancerFactoryto createLoadBalancerinstances.- Returns:
this.
-
sslConfig
Set the SSL/TLS configuration.- Parameters:
sslConfig- The configuration to use.- Returns:
this.- See Also:
-
inferPeerHost
Toggle inference of value to use instead ofClientSslConfig.peerHost()from client's address when peer host is not specified. By default, inference is enabled.- Parameters:
shouldInfer- value indicating whether inference is on (true) or off (false).- Returns:
this
-
inferPeerPort
Toggle inference of value to use instead ofClientSslConfig.peerPort()from client's address when peer port is not specified (equals-1). By default, inference is enabled.- Parameters:
shouldInfer- value indicating whether inference is on (true) or off (false).- Returns:
this
-
inferSniHostname
Toggle SNI hostname inference from client's address if not explicitly specified viasslConfig(ClientSslConfig). By default, inference is enabled.- Parameters:
shouldInfer- value indicating whether inference is on (true) or off (false).- Returns:
this
-
transportConfig
Set the transport configuration.- Parameters:
transportConfig-TransportConfigto use- Returns:
this- See Also:
-
buildStreaming
StreamingHttpClient buildStreaming()Builds a newStreamingHttpClient.- Returns:
- A new
StreamingHttpClient - Throws:
IllegalArgumentException- for incomplete or illegal configurationsIllegalStateException- for unsupported configuration combinations
-
build
Builds a newHttpClient.- Returns:
- A new
HttpClient
-
buildBlockingStreaming
Creates a newBlockingStreamingHttpClient.- Returns:
BlockingStreamingHttpClient
-
buildBlocking
Creates a newBlockingHttpClient.- Returns:
BlockingHttpClient
-
proxyConfig(ProxyConfig)withProxyConfig.forAddress(Object).