구성
먼저 공개 모듈을 고르고, DocumentStore 하나와 IndexStore 하나를 선택합니다. R2D1은 네 가지 backend 조합을 지원하지만 collection API는 하나입니다.
공개 모듈
Maven Central 배포 URL은 문서에서 가정하지 않습니다. 아래 coordinate만 애플리케이션의 version으로 추가하세요.
| 모듈 | Coordinate | 역할 |
|---|---|---|
| R2D1 | dev.nexcraft:r2d1 | 공통 API, R2 DocumentStore, D1 IndexStore |
| R2D1-FILESYSTEM | dev.nexcraft:r2d1-filesystem | Filesystem DocumentStore |
| R2D1-JDBC | dev.nexcraft:r2d1-jdbc | H2, HSQLDB, SQLite IndexStore |
| R2D1-MICRONAUT | dev.nexcraft:r2d1-micronaut | Micronaut 5 bean 통합 |
dependencies {
implementation("dev.nexcraft:r2d1:<version>")
implementation("dev.nexcraft:r2d1-filesystem:<version>")
implementation("dev.nexcraft:r2d1-jdbc:<version>")
implementation("dev.nexcraft:r2d1-micronaut:<version>")
}DocumentStore 선택
권위 있는 완전한 문서를 저장할 backend는 R2 또는 Filesystem 중 하나입니다. R2는 비동기 AWS SDK client를 사용하고, Filesystem은 애플리케이션이 제공한 executor에서 blocking I/O를 실행합니다.
IndexStore 선택
필터와 정렬에 사용하는 document identifier 및 @Index projection은 D1 또는 JDBC 중 하나에 저장합니다. D1은 Java HttpClient를 통한 REST transport이고, JDBC는 애플리케이션 소유 DataSource 경계를 사용합니다.
Resource 소유권
R2D1 adapter는 호출자가 제공한 DataSource, HttpClient, S3AsyncClient, Executor를 임의로 닫지 않습니다. adapter가 직접 만든 resource의 소유권만 해당 adapter 또는 execution 객체에 있습니다.
JDBC driver, connection pool, database server, Cloudflare account와 credential은 애플리케이션과 운영 환경이 소유합니다.
네 가지 조합
R2 + D1, R2 + JDBC, Filesystem + D1, Filesystem + JDBC를 선택할 수 있습니다. 두 store와 DocumentCodec을 PersistenceCollectionFactory에 전달하면 공통 R2D1Collection이 두 backend를 조정합니다.
R2D1 database =
R2D1.builder()
.collectionFactory(
new PersistenceCollectionFactory(
documentStore, indexStore, documentCodec, indexStore::initialize))
.build();
R2D1Collection<User> users = database.collection(User.class);