Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.
Perubahan Pelayan dari versi 1 ke versi 2
Topik ini merinci perubahan fungsi Pelayan dari versi 1 (v1) ke versi 2 (v2).
Tabel berikut menunjukkan perbedaan untuk pelayan DynamoDB secara khusus. Pelayan untuk layanan lain mengikuti pola yang sama.
Perubahan tingkat tinggi
Kelas pelayan berada dalam artefak Maven yang sama dengan layanan.
Perubahan |
v1 |
v2 |
Ketergantungan 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>
|
Nama paket |
com.amazonaws.services.dynamodbv2.waiters |
software.amazon.awssdk.services.dynamodb.waiters |
Nama kelas |
AmazonDynamoDBWaiters
|
|
1 Versi terbaru. 2 Versi terbaru.
APIperubahan
Perubahan |
v1 |
v2 |
Buat pelayan |
AmazonDynamoDB client = AmazonDynamoDBClientBuilder
.standard().build();
AmazonDynamoDBWaiters waiter = client.waiters();
|
Sinkron:DynamoDbClient client = DynamoDbClient.create();
DynamoDbWaiter waiter = client.waiter();
Asinkron: DynamoDbAsyncClient asyncClient =
DynamoDbAsyncClient.create();
DynamoDbAsyncWaiter waiter = asyncClient.waiter();
|
Tunggu sampai ada tabel |
Sinkron:waiter.tableExists()
.run(new WaiterParameters<>(
new DescribeTableRequest(tableName)));
Asinkron: 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();
|
Sinkron:
WaiterResponse<DescribeTableResponse> waiterResponse =
waiter.waitUntilTableExists(
r -> r.tableName("myTable"));
waiterResponse.matched().response()
.ifPresent(System.out::println);
Asinkron:
waiter.waitUntilTableExists(r -> r.tableName(tableName))
.whenComplete((r, t) -> {
if (t != null) {
t.printStackTrace();
} else {
System.out.println(
"Table creation succeeded");
}
}).join();
|
Perubahan konfigurasi
Perubahan |
v1 |
v2 |
Strategi Polling (upaya maksimal dan penundaan tetap) |
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));
|