Configuring the Netty-based HTTP client - AWS SDK for Java
AWS services or capabilities described in AWS documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with AWS services in China.

At Amazon Web Services (AWS), we’re focused on finding ways to improve our products and provide a better customer experience. To do that, we need your feedback. Please take 5 minutes of your time to share insights regarding your experience with Java Spring and your need for Spring integration with AWS.

Click here to take a quick survey

This survey is hosted by an external company (Qualtrics), so the link above does not lead to our website. Please note that AWS will own the data gathered via this survey, and will not share the information/results collected with survey respondents. AWS handles your information as described in the AWS Privacy Notice.

Configuring the Netty-based HTTP client

For asynchronous operations in the AWS SDK for Java 2.0, you can use Netty (NettyNioAsyncHttpClient) as the HTTP client or you can use the new AWS Common Runtime (CRT) HTTP client AwsCrtAsyncHttpClient. This topics shows you how to configure the Netty-based HTTP client.

For a full list of options you can set with these clients, see the AWS SDK for Java API Reference version 2.x.

Prerequisite

Before you can use use the Netty client, you need to configure your project dependencies in your pom.xml or build.gradle file to include version 2.0.0 or later of the artifactId netty-nio-client.

The following code example shows how to configure your project dependencies.

<dependency> <artifactId>netty-nio-client</artifactId> <groupId>software.amazon.awssdk</groupId> <version>2.0.0</version> </dependency>

Configuring service clients

Use the HTTP client builder to have the SDK manage its lifecycle. The HTTP client will be closed for you when the service client is shut down.

Imports

import software.amazon.awssdk.http.async.SdkAsyncHttpClient; import software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient; import software.amazon.awssdk.services.kinesis.KinesisAsyncClient;

Code

KinesisAsyncClient client = KinesisAsyncClient.builder() .httpClientBuilder(NettyNioAsyncHttpClient.builder() .maxConcurrency(100) .maxPendingConnectionAcquires(10_000)) .build();

You can also pass the HTTP client directly to the service client if you want to manage the lifecycle yourself.

Code

SdkAsyncHttpClient httpClient = NettyNioAsyncHttpClient.builder() .maxConcurrency(100) .maxPendingConnectionAcquires(10_000) .build(); KinesisAsyncClient kinesisClient = KinesisAsyncClient.builder() .httpClient(httpClient) .build(); httpClient.close();