【发布时间】:2022-08-12 16:33:46
【问题描述】:
我正在使用 vert.x,我正在尝试列出我的 DynamoDB 表。以下是我构建 DynamoDB 客户端的方法。
private static DynamoDbAsyncClient buildDynamoDBAsyncClient(final Vertx vertx) {
return VertxSdkClient.withVertx(DynamoDbAsyncClient.builder(), vertx.getOrCreateContext())
.build();
}
这是我提出的要求
CompletableFuture<ListTablesResponse> response = client.listTables(ListTablesRequest.builder()
.build());
// Map the response to another CompletableFuture containing just the table names
CompletableFuture<List<String>> tableNames = response.thenApply(ListTablesResponse::tableNames);
// When future is complete (either successfully or in error) handle the response
tableNames.whenComplete((tables, err) -> {
if (tables != null) {
tables.forEach(System.out::println);
} else {
// Handle error
err.printStackTrace();
}
client.close();
});
tableNames.join();
我收到阻塞线程的警告,然后是请求超时。我究竟做错了什么?先感谢您。
-
tableNames.join()阻塞线程直到操作完成。相反,它应该允许CompletableFuture传播给调用者。如果您包含更多上下文代码,我可以写一个更完整的答案 -
如果请求超时解决 Future 花费的时间比您的请求花费的时间要多... dynamoDb 非常慢,所以我想您需要更好的查询或处理后端中的内容,而不是在一个请求的范围内需要几秒钟才能完成。
标签: java amazon-dynamodb vert.x