服务员从版本 1 到版本 2 的变化 - Amazon SDK for Java 2.x
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

服务员从版本 1 到版本 2 的变化

本主题详细介绍了 Waiters 功能从版本 1 (v1) 到版本 2 (v2) 的变化。

下表具体说明了 DynamoDB 服务员的区别。其他服务的服务员也遵循同样的模式。

高级别更改

服务员的职业与该服务位于同一个 Maven 工件中。

更改 v1 v2

Maven 依赖项

<dependencyManagement> <dependencies> <dependency> <groupId>com.amazonaws</groupId> <artifactId>aws-java-sdk-bom</artifactId> <version>1.12.6801</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>com.amazonaws</groupId> <artifactId>dynamodb</artifactId> </dependency> </dependencies>
<dependencyManagement> <dependencies> <dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>bom</artifactId> <version>2.27.102</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>dynamodb</artifactId> </dependency> </dependencies>
软件包名称 com.amazonaws.services.dynamodbv2.waiters software.amazon.awssdk.services.dynamodb.waiters
类名

AmazonDynamoDBWaiters

1 最新版本2 最新版本

API改变

更改 v1 v2
创建服务员
AmazonDynamoDB client = AmazonDynamoDBClientBuilder .standard().build(); AmazonDynamoDBWaiters waiter = client.waiters();
同步:
DynamoDbClient client = DynamoDbClient.create(); DynamoDbWaiter waiter = client.waiter();

异步:

DynamoDbAsyncClient asyncClient = DynamoDbAsyncClient.create(); DynamoDbAsyncWaiter waiter = asyncClient.waiter();
等到表存在 同步:
waiter.tableExists() .run(new WaiterParameters<>( new DescribeTableRequest(tableName)));

异步:

waiter.tableExists() .runAsync(new WaiterParameters() .withRequest(new DescribeTableRequest(tableName)), new WaiterHandler() { @Override public void onWaitSuccess( AmazonWebServiceRequest amazonWebServiceRequest) { System.out.println("Table creation succeeded"); } @Override public void onWaitFailure(Exception e) { e.printStackTrace(); } }).get();

同步:

WaiterResponse<DescribeTableResponse> waiterResponse = waiter.waitUntilTableExists( r -> r.tableName("myTable")); waiterResponse.matched().response() .ifPresent(System.out::println);

异步:

waiter.waitUntilTableExists(r -> r.tableName(tableName)) .whenComplete((r, t) -> { if (t != null) { t.printStackTrace(); } else { System.out.println( "Table creation succeeded"); } }).join();

配置更改

更改 v1 v2
轮询策略(最大尝试次数和固定延迟)
MaxAttemptsRetryStrategy maxAttemptsRetryStrategy = new MaxAttemptsRetryStrategy(10); FixedDelayStrategy fixedDelayStrategy = new FixedDelayStrategy(3); PollingStrategy pollingStrategy = new PollingStrategy(maxAttemptsRetryStrategy, fixedDelayStrategy); waiter.tableExists().run( new WaiterParameters<>( new DescribeTableRequest(tableName)), pollingStrategy);
FixedDelayBackoffStrategy fixedDelayBackoffStrategy = FixedDelayBackoffStrategy .create(Duration.ofSeconds(3)); waiter.waitUntilTableExists(r -> r.tableName(tableName), c -> c.maxAttempts(10) .backoffStrategy(fixedDelayBackoffStrategy));