Forked from https://github.com/spotify/async-datastore-client
A modern, feature-rich and tunable Java client library for Google Cloud Datastore.
- Synchronous API design using Quasar that uses light-weight fiber 'threads' for asynchronous I/O under the covers
- Insulates the consumer from having to deal with Protobuf payloads.
- Includes a simple
QueryBuilderto construct natural looking queries.
The current implementations of Google Datastore Client and Google Cloud Java Client use blocking synchronous HTTP calls to their backend. This client uses FiberCloseableHttpAsyncClient which is Quasar fiber blocking version of the Apache Http Client
Add this to your pom.xml file
<dependency>
<groupId>com.spotify</groupId>
<artifactId>comsat-datastore-client</artifactId>
<version>1.0.0</version>
</dependency>import com.spotify.asyncdatastoreclient.DatastoreConfig;
import com.spotify.asyncdatastoreclient.Datastore;
import com.spotify.asyncdatastoreclient.QueryBuilder;
import com.spotify.asyncdatastoreclient.Insert;
import com.spotify.asyncdatastoreclient.MutationResult;
import com.google.api.services.datastore.client.DatastoreHelper;
import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.ListenableFuture;
final DatastoreConfig config = DatastoreConfig.builder()
.requestTimeout(1000)
.requestRetry(3)
.dataset(DATASET_ID);
.credential(DatastoreHelper.getServiceAccountCredential(ACCOUNT, KEY_PATH))
.build();
final Datastore datastore = Datastore.create(config);
final Insert insert = QueryBuilder.insert("employee", 1234567L)
.value("fullname", "Fred Blinge")
.value("age", 40)
.value("workdays", ImmutableList.of("Monday", "Tuesday", "Friday"));
final MutationResult result = datastore.execute(insert);import com.spotify.asyncdatastoreclient.QueryBuilder;
import com.spotify.asyncdatastoreclient.Query;
import static com.spotify.asyncdatastoreclient.QueryBuilder.eq;
import static com.spotify.asyncdatastoreclient.QueryBuilder.asc;
final Query query = QueryBuilder.query()
.kindOf("employee")
.filterBy(eq("role", "engineer"))
.orderBy(asc("age"));
// call datastore.executeAsync() to get a ListenableFuture<QueryResult>
for (final Entity entity : datastore.execute(query)) {
System.out.println("Name: " + entity.getString("fullname));
...
}mvn clean compileBy default integration tests are executed against a Local Development Server on port 8080. To run tests, first download the Development Server and create the local datastore as follows:
gcd.sh create -d async-test test-projectThis will create a project called test-project with a dataset ID of
async-test. You then start the server as follows:
gcd.sh start --consistency=1.0 test-projectNOTE: The
--consistency=1.0option is sometimes necessary in order for unit tests to run successful.
All integration tests may by run with maven as follows:
mvn verifyProperties may also be provided to override unit test configuration:
mvn verify -Dhost=https://www.googleapis.com -Ddataset=testing -Daccount=abc@developer.gserviceaccount.com -Dkeypath=./my-key-8ae3ab23d37.p12This software is released under the Apache License 2.0. More information in the file LICENSE distributed with this project.