GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — google-cloud-java/grpc-gcp-java at main · westarle/google-cloud-java

Expand file tree

/

grpc-gcp-java

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
 
 
/

grpc-gcp-java

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
src
src
 
 
.repo-metadata.json
.repo-metadata.json
 
 
CHANGELOG.md
CHANGELOG.md
 
 
README.md
README.md
 
 
pom.xml
pom.xml
 
 

README.md

Outline

gRPC-GCP for Java

grpc-gcp provides gRPC support for Google Cloud Clients.

This module is currently used by the Google Cloud Spanner client library to provide gRPC-GCP channel pooling and related transport behavior. It is published separately as com.google.cloud:grpc-gcp because Spanner exposes grpc-gcp types in its public API.

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/googleapis/google-cloud-java.git && cd google-cloud-java/grpc-gcp-java

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

Integration tests are kept as source references but are not wired into the default monorepo Maven lifecycle.

Publish

This artifact is released by the google-cloud-java monorepo release pipeline.

Code Format

Run google-java-format

mvn fmt:format
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.