Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

gRPC-GCP for Java

grpc-gcp provides gRPC support for Google Cloud Clients.

Usage

Use Spanner API as an example.

First, Create a json file defining API configuration, with ChannelPoolConfig and MethodConfig.

{
  "channelPool": {
    "maxSize": 3,
    "maxConcurrentStreamsLowWatermark": 0
  },
  "method": [
    {
      "name": [ "google.spanner.v1.Spanner/CreateSession" ],
      "affinity": {
        "command": "BIND",
        "affinityKey": "name"
      }
    },
    {
      "name": [ "google.spanner.v1.Spanner/GetSession" ],
      "affinity": {
        "command": "BOUND",
        "affinityKey": "name"
      }
    },
    {
      "name": [ "google.spanner.v1.Spanner/DeleteSession" ],
      "affinity": {
        "command": "UNBIND",
        "affinityKey": "name"
      }
    }
  ]
}

Initialize GcpManagedChannel based on this API config file.

String API_CONFIG_FILE = "api_config_file.json"
String SPANNER_TARGET = "spanner.googleapis.com";
...

ManagedChannelBuilder delegateChannelBuilder = ManagedChannelBuilder.forAddress(SPANNER_TARGET, 443);
GcpManagedChannelBuilder gcpBuilder = 
  GcpManagedChannelBuilder.forDelegateBuilder(delegateChannelBuilder)
                          .withApiConfigJsonFile(jsonApiConfig);
ManagedChannel gcpChannel = gcpBuilder.build();

Create Cloud API stub using GcpManagedChannel.

GoogleCredentials creds = getCreds();
SpannerBlockingStub stub =
    SpannerGrpc.newBlockingStub(gcpChannel)
               .withCallCredentials(MoreCallCredentials.from(creds));

Build from source

Download source.

git clone https://github.com/GoogleCloudPlatform/grpc-gcp-java.git && cd grpc-gcp-java/grpc-gcp

Build project with unit tests.

mvn verify

Install the jar to your local Maven repository.

mvn install

Test

Setup credentials. See Getting Started With Authentication for more details.

export GOOGLE_APPLICATION_CREDENTIALS=path/to/key.json
export GCP_PROJECT_ID=project_id

Run unit tests.

mvn test

Run unit tests and integration tests:

mvn verify -DskipITs=false

Publish

Publish a release build using the Maven release profile inherited from shared config.

mvn deploy -DperformRelease=true

Code Format

Run google-java-format

mvn fmt:format