CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-software-amazon-awssdk--netty-nio-client

A non-blocking HTTP client implementation for AWS SDK Java applications using Netty framework, enabling efficient network communication with AWS services through asynchronous I/O operations

Overview
Eval results
Files

http-client.mddocs/

HTTP Client Configuration

Comprehensive configuration options for the NettyNioAsyncHttpClient including connection management, timeouts, protocol selection, and advanced Netty-specific settings.

Capabilities

NettyNioAsyncHttpClient

The main HTTP client implementation providing asynchronous HTTP communication with AWS services.

/**
 * NettyNioAsyncHttpClient provides non-blocking HTTP communication using Netty NIO.
 * Supports HTTP/1.1 and HTTP/2 with configurable connection pooling and timeouts.
 */
public final class NettyNioAsyncHttpClient implements SdkAsyncHttpClient {
    /**
     * Executes an asynchronous HTTP request
     * @param request the HTTP request to execute including headers, body, and response handler
     * @return CompletableFuture that completes when the response is fully processed
     */
    public CompletableFuture<Void> execute(AsyncExecuteRequest request);
    
    /**
     * Closes the HTTP client and releases all resources including connection pools and event loops
     */
    public void close();
    
    /**
     * Returns the client name identifier
     * @return "NettyNio" - the client identifier constant
     */
    public String clientName();
    
    /**
     * Creates a new builder for configuring the HTTP client
     * @return new Builder instance
     */
    public static Builder builder();
    
    /**
     * Creates an HTTP client with default configuration
     * @return configured SdkAsyncHttpClient instance
     */
    public static SdkAsyncHttpClient create();
}

Usage Examples:

import software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient;
import software.amazon.awssdk.core.client.config.SdkClientConfiguration;

// Default configuration
SdkAsyncHttpClient client = NettyNioAsyncHttpClient.create();

// Custom configuration
SdkAsyncHttpClient client = NettyNioAsyncHttpClient.builder()
    .maxConcurrency(50)
    .connectionTimeout(Duration.ofSeconds(10))
    .readTimeout(Duration.ofSeconds(30))
    .writeTimeout(Duration.ofSeconds(30))
    .protocol(Protocol.HTTP2)
    .build();

// Use with AWS service
S3AsyncClient s3 = S3AsyncClient.builder()
    .httpClient(client)
    .build();

Builder Configuration

Comprehensive builder interface for configuring NettyNioAsyncHttpClient instances.

/**
 * Builder interface for configuring NettyNioAsyncHttpClient instances
 */
public interface Builder extends SdkAsyncHttpClient.Builder<Builder> {
    /**
     * Sets the maximum number of concurrent connections/requests
     * @param maxConcurrency maximum concurrency (default: 50)
     * @return this builder for method chaining
     */
    Builder maxConcurrency(Integer maxConcurrency);
    
    /**
     * Sets the maximum number of pending connection acquisitions from the pool
     * @param maxPendingConnectionAcquires maximum pending acquisitions (default: 10000)
     * @return this builder for method chaining
     */
    Builder maxPendingConnectionAcquires(Integer maxPendingConnectionAcquires);
    
    /**
     * Sets the socket read timeout duration
     * @param readTimeout read timeout (default: 30 seconds)
     * @return this builder for method chaining
     */
    Builder readTimeout(Duration readTimeout);
    
    /**
     * Sets the socket write timeout duration
     * @param writeTimeout write timeout (default: 30 seconds)
     * @return this builder for method chaining
     */
    Builder writeTimeout(Duration writeTimeout);
    
    /**
     * Sets the connection establishment timeout
     * @param connectionTimeout connection timeout (default: 10 seconds)
     * @return this builder for method chaining
     */
    Builder connectionTimeout(Duration connectionTimeout);
    
    /**
     * Sets the connection pool acquisition timeout
     * @param connectionAcquisitionTimeout acquisition timeout (default: 10 seconds)
     * @return this builder for method chaining
     */
    Builder connectionAcquisitionTimeout(Duration connectionAcquisitionTimeout);
    
    /**
     * Sets the maximum connection lifetime (time-to-live)
     * @param connectionTimeToLive connection TTL (default: infinite)
     * @return this builder for method chaining
     */
    Builder connectionTimeToLive(Duration connectionTimeToLive);
    
    /**
     * Sets the maximum connection idle time before closure
     * @param connectionMaxIdleTime max idle time (default: 60 seconds)
     * @return this builder for method chaining
     */
    Builder connectionMaxIdleTime(Duration connectionMaxIdleTime);
    
    /**
     * Sets the TLS handshake timeout duration
     * @param tlsNegotiationTimeout TLS timeout (default: 10 seconds)
     * @return this builder for method chaining
     */
    Builder tlsNegotiationTimeout(Duration tlsNegotiationTimeout);
    
    /**
     * Enables or disables idle connection cleanup
     * @param useIdleConnectionReaper true to enable reaper (default: true)
     * @return this builder for method chaining
     */
    Builder useIdleConnectionReaper(Boolean useIdleConnectionReaper);
    
    /**
     * Sets custom event loop group (caller manages lifecycle)
     * @param eventLoopGroup custom event loop group
     * @return this builder for method chaining
     */
    Builder eventLoopGroup(SdkEventLoopGroup eventLoopGroup);
    
    /**
     * Sets event loop group builder (SDK manages lifecycle)
     * @param eventLoopGroupBuilder event loop builder
     * @return this builder for method chaining
     */
    Builder eventLoopGroupBuilder(SdkEventLoopGroup.Builder eventLoopGroupBuilder);
    
    /**
     * Sets the HTTP protocol version
     * @param protocol HTTP/1.1 or HTTP/2 (default: HTTP/1.1)
     * @return this builder for method chaining
     */
    Builder protocol(Protocol protocol);
    
    /**
     * Sets the protocol negotiation strategy
     * @param protocolNegotiation ALPN or ASSUME_PROTOCOL (default: ALPN for HTTPS)
     * @return this builder for method chaining
     */
    Builder protocolNegotiation(ProtocolNegotiation protocolNegotiation);
    
    /**
     * Enables or disables TCP keep-alive
     * @param tcpKeepAlive true to enable keep-alive (default: false)
     * @return this builder for method chaining
     */
    Builder tcpKeepAlive(Boolean tcpKeepAlive);
    
    /**
     * Adds a custom Netty channel option
     * @param channelOption the channel option to set
     * @param value the value for the option
     * @return this builder for method chaining
     */
    Builder putChannelOption(ChannelOption channelOption, Object value);
    
    /**
     * Sets the maximum number of concurrent HTTP/2 streams per connection
     * @param maxHttp2Streams maximum concurrent HTTP/2 streams
     * @return this builder for method chaining
     * @deprecated Use http2Configuration(Http2Configuration) with Http2Configuration.Builder.maxStreams(Long) instead
     */
    @Deprecated
    Builder maxHttp2Streams(Integer maxHttp2Streams);
    
    /**
     * Sets the SSL provider implementation
     * @param sslProvider JDK, OPENSSL, or OPENSSL_REFCNT (default: OPENSSL if available)
     * @return this builder for method chaining
     */
    Builder sslProvider(SslProvider sslProvider);
    
    /**
     * Sets proxy configuration
     * @param proxyConfiguration proxy settings
     * @return this builder for method chaining
     */
    Builder proxyConfiguration(ProxyConfiguration proxyConfiguration);
    
    /**
     * Sets TLS key managers provider for client certificates
     * @param tlsKeyManagersProvider key manager provider
     * @return this builder for method chaining
     */
    Builder tlsKeyManagersProvider(TlsKeyManagersProvider tlsKeyManagersProvider);
    
    /**
     * Sets TLS trust managers provider for server certificate validation
     * @param tlsTrustManagersProvider trust manager provider
     * @return this builder for method chaining
     */
    Builder tlsTrustManagersProvider(TlsTrustManagersProvider tlsTrustManagersProvider);
    
    /**
     * Sets HTTP/2 specific configuration
     * @param http2Configuration HTTP/2 settings
     * @return this builder for method chaining
     */
    Builder http2Configuration(Http2Configuration http2Configuration);
    
    /**
     * Sets HTTP/2 configuration via consumer
     * @param http2ConfigurationBuilder consumer to configure HTTP/2 settings
     * @return this builder for method chaining
     */
    Builder http2Configuration(Consumer<Http2Configuration.Builder> http2ConfigurationBuilder);
    
    /**
     * Enables or disables non-blocking DNS resolution
     * @param useNonBlockingDnsResolver true to enable non-blocking DNS (default: true)
     * @return this builder for method chaining
     */
    Builder useNonBlockingDnsResolver(Boolean useNonBlockingDnsResolver);
    
    /**
     * Builds the configured NettyNioAsyncHttpClient
     * @return configured HTTP client instance
     */
    NettyNioAsyncHttpClient build();
}

Configuration Examples:

// High-throughput configuration
NettyNioAsyncHttpClient client = NettyNioAsyncHttpClient.builder()
    .maxConcurrency(200)
    .maxPendingConnectionAcquires(1000)
    .connectionTimeout(Duration.ofSeconds(5))
    .readTimeout(Duration.ofMinutes(2))
    .writeTimeout(Duration.ofMinutes(2))
    .connectionMaxIdleTime(Duration.ofMinutes(1))
    .useIdleConnectionReaper(true)
    .protocol(Protocol.HTTP2)
    .tcpKeepAlive(true)
    .build();

// Custom event loop configuration
SdkEventLoopGroup eventLoopGroup = SdkEventLoopGroup.builder()
    .numberOfThreads(8)
    .build();
    
NettyNioAsyncHttpClient client = NettyNioAsyncHttpClient.builder()
    .eventLoopGroup(eventLoopGroup)
    .build();

// SSL/TLS configuration
NettyNioAsyncHttpClient client = NettyNioAsyncHttpClient.builder()
    .sslProvider(SslProvider.OPENSSL)
    .tlsNegotiationTimeout(Duration.ofSeconds(15))
    .tlsKeyManagersProvider(myKeyManagersProvider)
    .tlsTrustManagersProvider(myTrustManagersProvider)
    .build();

Types

Core HTTP Types

interface SdkAsyncHttpClient extends SdkHttpClient {
    CompletableFuture<Void> execute(AsyncExecuteRequest request);
    void close();
    String clientName();
}

interface AsyncExecuteRequest {
    SdkHttpRequest request();
    AsyncRequestBody requestBody();
    ResponseHandler responseHandler();
}

enum Protocol {
    HTTP1_1,  // HTTP/1.1 protocol
    HTTP2     // HTTP/2 protocol
}

enum ProtocolNegotiation {
    ALPN,              // Application Layer Protocol Negotiation
    ASSUME_PROTOCOL    // Assume configured protocol without negotiation
}

enum SslProvider {
    JDK,               // Use JDK's SSL implementation
    OPENSSL,           // Use OpenSSL implementation
    OPENSSL_REFCNT     // Use OpenSSL with reference counting
}

Netty Channel Configuration

// Common Netty channel options that can be used with putChannelOption()
class ChannelOption<T> {
    static final ChannelOption<Boolean> SO_KEEPALIVE;
    static final ChannelOption<Boolean> TCP_NODELAY;
    static final ChannelOption<Integer> SO_TIMEOUT;
    static final ChannelOption<Integer> CONNECT_TIMEOUT_MILLIS;
}

Install with Tessl CLI

npx tessl i tessl/maven-software-amazon-awssdk--netty-nio-client

docs

event-loop.md

http-client.md

http2-config.md

index.md

proxy-config.md

tile.json