我可以使用以下代码在 DynamoDB 中插入一个对象(用@DynamoDBTable 注释)
@Autowired
private SdnInformationRepository sdnInformationRepository;
SdnInformation inf = new SdnInformation();
inf.setFirstName("firstname");
inf.setLastName("lastname");
sdnInformationRepository.save(inf);
这是我的仓库
public interface SdnInformationRepository extends
CrudRepository<SdnInformation, String> {
}
和我的模型
@DynamoDBTable(tableName = "SdnList")
public class SdnInformation {
@DynamoDBHashKey(attributeName = "Id")
@DynamoDBAutoGeneratedKey
private String id;
private String firstName;
private String lastName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
这里一切正常。我想知道是否可以一次插入一个 List/Set 的 SdnInformation 对象?如果我单独插入大量此类对象,则会花费太多时间。 所以我想要类似的东西
Set<SdnInformation> listToInsert = new HashSet<SdnInformation>();
... some code to fill my set with thousands of objects ...
sdnInformationRepository.save(listToInsert);
最佳答案
DynamoDB 不支持同时插入多个项目。批处理多个请求(最多 25 个)是可能的,但它们仍然被 Dynamo 视为单独的请求(即,有可能一些成功,一些失败)。
当然,在高层次上,映射器可以假装它正在插入一个项目列表,但在底层仍然会有单独的操作。
更新(基于评论)
如果您追求的是速度,则可以并行化插入。只要您有可用的写入容量,您就可以通过这种方式获得很大的速度提升。但它很快就会变得昂贵。每个分区的插入次数限制为每秒 1000 次。
关于java - 是否可以一次性将一组对象插入 DynamoDB - Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52278615/