Releases: stargate/stargate-sdk-java
Version 2.1.2
2.0.2
2.0.1
Reflecting changes with Stargate v2 architecture each Api client is now independent and got its own module.
The stargate SDK lives as a standalone project (previous it was under the umbrella of astra-sdk
[INFO] Stargate SDK Java .................................. SUCCESS [ 0.044 s]
[INFO] + stargate-sdk-commons ............................. SUCCESS [ 0.001 s]
[INFO] + stargate-sdk-cql ................................. SUCCESS [ 0.000 s]
[INFO] + stargate-sdk-document ............................ SUCCESS [ 0.000 s]
[INFO] + stargate-sdk-graphql ............................. SUCCESS [ 0.004 s]
[INFO] + stargate-sdk-grpc ................................ SUCCESS [ 0.000 s]
[INFO] + stargate-sdk-rest ................................ SUCCESS [ 0.001 s]
[INFO] + stargate-sdk ..................................... SUCCESS [ 0.000 s]
[INFO] + stargate-sdk-test ................................ SUCCESS [ 0.000 s]
[INFO] ------------------------------------------------------------------------
ServiceDeployments
A ServiceDeployment
is created for each API type (grpc, rest, doc, graphql). In a service deployment you find a list of ServiceDataCenter
In a ServiceDatacenter you find a list of Service
. The SDK allows load balancing across the different services of a same Datacenter and fail-over across datacenters. If no explicit ServiceDeployment
is provided the client will initialize with development configuration. (single node localhost, default ports).
A TokenProvider
needs to be defined for datacenter. It will generate and renewed token whenever needed.
Both syntax belows are even:
- Default
StargateRestApiClient restClient = new StargateRestApiClient();
- Explicit Configuration
// Single Endpoint (dev)
ServiceHttp rest = new ServiceHttp("rest1", "http://localhost:8082", "http://localhost:8082/stargate/health");
// Default Authentication Endpoint (dev)
TokenProvider tokenProvider = new TokenProviderHttpAuth("cassandra", "cassandra", "http://localhost:8081");
// A Service Datacenter with a single Service
ServiceDatacenter<ServiceHttp> dc1 = new ServiceDatacenter<>("dc1", tokenProvider, Collections.singletonList(rest));
// A service deployment with a single DC
ServiceDeployment<ServiceHttp> deploy = new ServiceDeployment<ServiceHttp>().addDatacenter(dc1);
// Initialization of the service
StargateRestApiClient restClient1 = new StargateRestApiClient(deploy);
- If you want to scale out the rest API with 3 nodes on the dc
ServiceHttp dc1Node1 = new ServiceHttp("dc1Node1", "http://node1:8082", "http://node1:8082/stargate/health");
ServiceHttp dc1Node2 = new ServiceHttp("dc1Node2", "http://node2:8082", "http://node2:8082/stargate/health");
ServiceHttp dc1Node3 = new ServiceHttp("dc1Node3", "http://node3:8082", "http://node3:8082/stargate/health");
TokenProvider dc1TokenProvider = new TokenProviderHttpAuth("cassandra", "cassandra", "http://localhost:8081");
ServiceDatacenter<ServiceHttp> dc1 = new ServiceDatacenter<>("dc1", dc1TokenProvider, dc1Node1, dc1Node2, dc1Node3);
// ...
Getting Started
- Add dependency to your project, pick the API you need.
<dependency>
<groupId>com.datastax.stargate</groupId>
<artifactId>stargate-sdk-grpc</artifactId>
<version>2.0.1</version>
</dependency>
- Initialize the SDK client based on your architecture (Service Deployment, see above)
// Dev config (localhost:8090 with auth on localhost8081
StargateGrpcApiClient sdkGrpcClient = new StargateGrpcApiClient();
- Enjoy
System.out.println(sdkGrpcClient
.execute("SELECT data_center from system.local")
.one()
.getString("data_center"));
CompletableFuture<ResultSetGrpc> rs =
sdkGrpcClient.executeAsync("SELECT * FROM table where PK =?", "pk_value");