Skip to content

Commit

Permalink
docs: Update documentation to encourage using Cloud Resource header f…
Browse files Browse the repository at this point in the history
…or gRPC connections

PiperOrigin-RevId: 459427019
  • Loading branch information
On Demand Rides and Deliveries authored and copybara-github committed Jul 7, 2022
1 parent 64cf113 commit 178382d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,20 @@ functionality to be injected using interceptors.
Using GAPIC clients in lieu of gRPC stubs is recommended.

```java
// In most cases, tokenProvider will be a singleton instance of AuthTokenMinter.
FleetEngineTokenProvider fleetEngineTokenProvider = getTokenProvider();

// Cloud resource prefix allows optimised request handling.
Metadata headers = new Metadata();
headers.put(
Metadata.Key.of(
"google-cloud-resource-prefix", Metadata.ASCII_STRING_MARSHALLER),
String.format("providers/%s", PROVIDER_ID));

ManagedChannel channel = ManagedChannelBuilder.forTarget(fleetEngineAddress)
//In most cases, tokenProvider will be a singleton instance of AuthTokenMinter
.intercept(FleetEngineAuthClientInterceptor.create(fleetEngineTokenProvider))
.intercept(
FleetEngineAuthClientInterceptor.create(fleetEngineTokenProvider),
MetadataUtils.newAttachHeadersInterceptor(headers))
.build();

VehicleServiceBlockingStub stub = VehicleServiceGrpc.newBlockingStub(channel);
Expand Down

0 comments on commit 178382d

Please sign in to comment.