public class NettyAsyncHttpClientBuilder extends Object
HttpClient backed by Reactor Netty.
Building a new HttpClient instance
HttpClient client = new NettyAsyncHttpClientBuilder()
.port(8080)
.wiretap(true)
.build();
HttpClient| Constructor and Description |
|---|
NettyAsyncHttpClientBuilder()
Creates a new builder instance, where a builder is capable of generating multiple instances of
HttpClient backed by Reactor Netty. |
NettyAsyncHttpClientBuilder(reactor.netty.http.client.HttpClient nettyHttpClient)
Creates a new builder instance, where a builder is capable of generating multiple instances of
HttpClient based on the provided Reactor Netty HttpClient. |
| Modifier and Type | Method and Description |
|---|---|
HttpClient |
build()
Creates a new Netty-backed
HttpClient instance on every call, using the configuration
set in the builder at the time of the build method call. |
NettyAsyncHttpClientBuilder |
configuration(Configuration configuration)
Sets the configuration store that is used during construction of the HTTP client.
|
NettyAsyncHttpClientBuilder |
connectionProvider(reactor.netty.resources.ConnectionProvider connectionProvider)
Sets the connection provider.
|
NettyAsyncHttpClientBuilder |
disableBufferCopy(boolean disableBufferCopy)
Disables deep copy of response
ByteBuffer into a heap location that is managed by this client as opposed
to the underlying netty library which may use direct buffer pool. |
NettyAsyncHttpClientBuilder |
eventLoopGroup(EventLoopGroup eventLoopGroup)
Sets the IO event loop group that will be used to run IO loops.
|
NettyAsyncHttpClientBuilder |
nioEventLoopGroup(NioEventLoopGroup nioEventLoopGroup)
Deprecated.
deprecated in favor of
NettyAsyncHttpClientBuilder.eventLoopGroup(EventLoopGroup). |
NettyAsyncHttpClientBuilder |
port(int port)
Sets the port which this client should connect, which by default will be set to port 80.
|
NettyAsyncHttpClientBuilder |
proxy(ProxyOptions proxyOptions)
Sets the
proxy options that the client will use. |
NettyAsyncHttpClientBuilder |
readTimeout(Duration readTimeout)
Sets the read timeout duration used when reading the server response.
|
NettyAsyncHttpClientBuilder |
responseTimeout(Duration responseTimeout)
Sets the response timeout duration used when waiting for a server to reply.
|
NettyAsyncHttpClientBuilder |
wiretap(boolean enableWiretap)
Enables the Netty wiretap feature.
|
NettyAsyncHttpClientBuilder |
writeTimeout(Duration writeTimeout)
Sets the write timeout for a request to be sent.
|
public NettyAsyncHttpClientBuilder()
HttpClient backed by Reactor Netty.public NettyAsyncHttpClientBuilder(reactor.netty.http.client.HttpClient nettyHttpClient)
HttpClient based on the provided Reactor Netty HttpClient.
// Creates a reactor-netty client with netty logging enabled.
reactor.netty.http.client.HttpClient baseHttpClient = reactor.netty.http.client.HttpClient.create()
.tcpConfiguration(tcp -> tcp.bootstrap(b -> b.handler(new LoggingHandler(LogLevel.INFO))));
// Create an HttpClient based on above reactor-netty client and configure EventLoop count.
HttpClient client = new NettyAsyncHttpClientBuilder(baseHttpClient)
.eventLoopGroup(new NioEventLoopGroup(5))
.build();
nettyHttpClient - base reactor netty HttpClientpublic HttpClient build()
HttpClient instance on every call, using the configuration
set in the builder at the time of the build method call.HttpClient instance.IllegalStateException - If the builder is configured to use an unknown proxy type.public NettyAsyncHttpClientBuilder connectionProvider(reactor.netty.resources.ConnectionProvider connectionProvider)
connectionProvider - the connection providerNettyAsyncHttpClientBuilder object.public NettyAsyncHttpClientBuilder proxy(ProxyOptions proxyOptions)
proxy options that the client will use.proxyOptions - The proxy configuration to use.public NettyAsyncHttpClientBuilder wiretap(boolean enableWiretap)
enableWiretap - Flag indicating wiretap statuspublic NettyAsyncHttpClientBuilder port(int port)
port - The port to connect to.@Deprecated public NettyAsyncHttpClientBuilder nioEventLoopGroup(NioEventLoopGroup nioEventLoopGroup)
NettyAsyncHttpClientBuilder.eventLoopGroup(EventLoopGroup).nioEventLoopGroup - The NioEventLoopGroup that will run IO loops.public NettyAsyncHttpClientBuilder eventLoopGroup(EventLoopGroup eventLoopGroup)
Code Samples
int threadCount = 5;
HttpClient client = new NettyAsyncHttpClientBuilder()
.eventLoopGroup(new NioEventLoopGroup(threadCount))
.build();
eventLoopGroup - The EventLoopGroup that will run IO loops.public NettyAsyncHttpClientBuilder configuration(Configuration configuration)
The default configuration store is a clone of the global
configuration store, use Configuration.NONE to bypass using configuration settings during construction.
configuration - The configuration store used topublic NettyAsyncHttpClientBuilder disableBufferCopy(boolean disableBufferCopy)
ByteBuffer into a heap location that is managed by this client as opposed
to the underlying netty library which may use direct buffer pool.
ByteBuffer
upon the return of onNext(). So, users should ensure they process the ByteBuffer immediately and
then return.
HttpClient client = new NettyAsyncHttpClientBuilder()
.port(8080)
.disableBufferCopy(true)
.build();
client.send(httpRequest)
.flatMapMany(response -> response.getBody())
.map(byteBuffer -> completeProcessingByteBuffer(byteBuffer))
.subscribe();
disableBufferCopy - If set to true, the client built from this builder will not deep-copy response
ByteBuffers.NettyAsyncHttpClientBuilder object.public NettyAsyncHttpClientBuilder writeTimeout(Duration writeTimeout)
The write timeout does not apply to the entire request but to the request being sent over the wire. For example a
request body which emits 10 8KB buffers will trigger 10 write operations, the last write
tracker will update when each operation completes and the outbound buffer will be periodically checked to
determine if it is still draining.
If writeTimeout is null is null a 60 second timeout will be used, if it is a Duration less than or equal to zero then no write timeout will be applied. When applying the timeout the greater
of one millisecond and the value of writeTimeout will be used.
writeTimeout - Write operation timeout duration.NettyAsyncHttpClientBuilder object.public NettyAsyncHttpClientBuilder responseTimeout(Duration responseTimeout)
The response timeout begins once the request write completes and finishes once the first response read is triggered when the server response is received.
If responseTimeout is null a 60 second timeout will be used, if it is a Duration less
than or equal to zero then no timeout will be applied to the response. When applying the timeout the greater of
one millisecond and the value of responseTimeout will be used.
responseTimeout - Response timeout duration.NettyAsyncHttpClientBuilder object.public NettyAsyncHttpClientBuilder readTimeout(Duration readTimeout)
The read timeout begins once the first response read is triggered after the server response is received. This timeout triggers periodically but won't fire its operation if another read operation has completed between when the timeout is triggered and completes.
If readTimeout is null a 60 second timeout will be used, if it is a Duration less than or
equal to zero then no timeout period will be applied to response read. When applying the timeout the greater of
one millisecond and the value of readTimeout will be used.
readTimeout - Read timeout duration.NettyAsyncHttpClientBuilder object.Copyright © 2020 Microsoft Corporation. All rights reserved.