Ada lebih banyak contoh AWS SDK yang tersedia di repo Contoh SDK AWS Doc. GitHub
Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.
Contoh kode untuk Neptunus menggunakan AWS SDKs
Contoh kode berikut menunjukkan cara menggunakan Amazon Neptunus dengan kit pengembangan perangkat lunak ( AWS SDK).
Dasar-dasar adalah contoh kode yang menunjukkan kepada Anda bagaimana melakukan operasi penting dalam suatu layanan.
Tindakan merupakan kutipan kode dari program yang lebih besar dan harus dijalankan dalam konteks. Sementara tindakan menunjukkan cara memanggil fungsi layanan individual, Anda dapat melihat tindakan dalam konteks dalam skenario terkait.
Skenario adalah contoh kode yang menunjukkan kepada Anda bagaimana menyelesaikan tugas tertentu dengan memanggil beberapa fungsi dalam layanan atau dikombinasikan dengan yang lain Layanan AWS.
Sumber daya lainnya
Panduan Pengguna Neptunus — Informasi lebih lanjut tentang Neptunus.
Referensi API Neptunus — Detail tentang semua tindakan Neptunus yang tersedia.
AWS Pusat Pengembang - Contoh kode yang dapat Anda filter berdasarkan kategori atau pencarian teks lengkap.
AWS Contoh SDK — GitHub repo dengan kode lengkap dalam bahasa pilihan. Termasuk instruksi untuk mengatur dan menjalankan kode.
Memulai
Contoh kode berikut menunjukkan bagaimana memulai menggunakan Neptunus.
- Java
-
- SDK untuk Java 2.x
-
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankannya di Repositori Contoh Kode AWS.
/**
* Before running this Java V2 code example, set up your development
* environment, including your credentials.
*
* For more information, see the following documentation topic:
*
* https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html
*/
public class HelloNeptune {
public static void main(String[] args) {
NeptuneAsyncClient neptuneClient = NeptuneAsyncClient.create();
describeDbCluster(neptuneClient).join(); // This ensures the async code runs to completion
}
/**
* Describes the Amazon Neptune DB clusters.
*
* @param neptuneClient the Neptune asynchronous client used to make the request
* @return a {@link CompletableFuture} that completes when the operation is finished
*/
public static CompletableFuture<Void> describeDbCluster(NeptuneAsyncClient neptuneClient) {
DescribeDbClustersRequest request = DescribeDbClustersRequest.builder()
.maxRecords(20)
.build();
SdkPublisher<DescribeDbClustersResponse> paginator = neptuneClient.describeDBClustersPaginator(request);
CompletableFuture<Void> future = new CompletableFuture<>();
paginator.subscribe(new Subscriber<DescribeDbClustersResponse>() {
private Subscription subscription;
@Override
public void onSubscribe(Subscription s) {
this.subscription = s;
s.request(Long.MAX_VALUE); // request all items
}
@Override
public void onNext(DescribeDbClustersResponse response) {
response.dbClusters().forEach(cluster -> {
System.out.println("Cluster Identifier: " + cluster.dbClusterIdentifier());
System.out.println("Status: " + cluster.status());
});
}
@Override
public void onError(Throwable t) {
future.completeExceptionally(t);
}
@Override
public void onComplete() {
future.complete(null);
}
});
return future.whenComplete((result, throwable) -> {
neptuneClient.close();
if (throwable != null) {
System.err.println("Error describing DB clusters: " + throwable.getMessage());
}
});
}