Name: async-datastore-client
Owner: Spotify
Description: A modern and feature-rich Asynchronous Java client for Google Cloud Datastore
Created: 2015-06-16 09:29:00.0
Updated: 2018-05-17 08:24:19.0
Pushed: 2018-04-23 16:01:25.0
Homepage: null
Size: 118
Language: Java
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
A modern, feature-rich and tunable Java client library for Google Cloud Datastore.
QueryBuilder
to construct natural looking queries.The current implementations of Google Datastore Client
and Google Cloud Java Client
are synchronous, meaning they block when making HTTP calls to their backend.
This client uses async-http-client
and returns ListenableFutures
which can be nicer to work with, especially
running at scale.
Add this to your pom.xml file
endency>
roupId>com.spotify</groupId>
rtifactId>async-datastore-client</artifactId>
ersion>3.0.2</version>
pendency>
NOTE: Version 3.0.0+ depends on Guava 19 which contains breaking changes to
Futures.transform
. If you require support for Guava version 18 or lower then use async-datastore-client version 2.1.0.
rt com.spotify.asyncdatastoreclient.DatastoreConfig;
rt com.spotify.asyncdatastoreclient.Datastore;
rt com.spotify.asyncdatastoreclient.QueryBuilder;
rt com.spotify.asyncdatastoreclient.Insert;
rt com.spotify.asyncdatastoreclient.MutationResult;
rt com.google.api.services.datastore.client.DatastoreHelper;
rt com.google.common.collect.ImmutableList;
rt com.google.common.util.concurrent.ListenableFuture;
l DatastoreConfig config = DatastoreConfig.builder()
.requestTimeout(1000)
.requestRetry(3)
.project(PROJECT_ID)
.credential(GoogleCredential
.fromStream(credentialsInputStream)
.createScoped(DatastoreConfig.SCOPES))
.build();
l Datastore datastore = Datastore.create(config);
l Insert insert = QueryBuilder.insert("employee", 1234567L)
.value("fullname", "Fred Blinge")
.value("age", 40)
.value("workdays", ImmutableList.of("Monday", "Tuesday", "Friday"));
or asynchronous call...
l ListenableFuture<MutationResult> resultAsync = datastore.executeAsync(insert);
..or for synchronous
l MutationResult result = datastore.execute(insert);
rt com.spotify.asyncdatastoreclient.QueryBuilder;
rt com.spotify.asyncdatastoreclient.Query;
rt static com.spotify.asyncdatastoreclient.QueryBuilder.eq;
rt static com.spotify.asyncdatastoreclient.QueryBuilder.asc;
l Query query = QueryBuilder.query()
.kindOf("employee")
.filterBy(eq("role", "engineer"))
.orderBy(asc("age"));
all datastore.executeAsync() to get a ListenableFuture<QueryResult>
(final Entity entity : datastore.execute(query)) {
stem.out.println("Name: " + entity.getString("fullname));
.
clean compile
By default integration tests are executed against a Local Development Server on port 8080. To run tests, first download the Development Server, at least version 1.4.1 and start the emulator:
ud beta emulators datastore start --host-port localhost:8080 --consistency 1.0 --project async-test --data-dir project-test
NOTE: The
--consistency=1.0
option is sometimes necessary in order for unit tests to run successful.
All integration tests may by run with maven as follows:
verify
Properties may also be provided to override unit test configuration:
verify -Dhost=https://www.googleapis.com -Dproject=testing -Dkeypath=./my-key.json
This software is released under the Apache License 2.0. More information in the file LICENSE distributed with this project.