Skip to content

Commit 520e351

Browse files
committed
fix: Undo merge mistakes
1 parent f13184e commit 520e351

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed

README.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,102 @@ running on Compute Engine or from your own desktop. To run the example on App En
210210
the code from the main method to your application's servlet class and change the print statements to
211211
display on your webpage.
212212

213+
gRPC Java Datastore Client User Guide
214+
-------
215+
In this feature launch, the [Java Datastore client](https://github.com/googleapis/java-datastore) now offers gRPC as a transport layer option with experimental support. Using [gRPC connection pooling](https://grpc.io/docs/guides/performance/) enables distributing RPCs over multiple connections which may improve performance.
216+
217+
#### Download Instructions
218+
Instructions:
219+
1. Clone the grpc-experimental branch from GitHub:
220+
```python
221+
git clone -b grpc-experimental https://github.com/googleapis/java-datastore.git
222+
```
223+
2. Run the following commands to build the library:
224+
```python
225+
# Go to the directory the code was downloaded to
226+
cd java-datastore/
227+
228+
# Build the library
229+
mvn clean install -DskipTests=true
230+
```
231+
3. Add the following dependency to your project:
232+
```xml
233+
<dependency>
234+
<groupId>com.google.cloud</groupId>
235+
<artifactId>google-cloud-datastore</artifactId>
236+
<version>2.20.0-grpc-experimental-1-SNAPSHOT</version>
237+
</dependency>
238+
```
239+
240+
#### How to Use
241+
To opt-in to the gRPC transport behavior, simply add the below line of code (`setTransportOptions`) to your Datastore client instantiation.
242+
243+
Example:
244+
```java
245+
DatastoreOptions datastoreOptions =
246+
DatastoreOptions.newBuilder()
247+
.setProjectId("my-project")
248+
.setDatabaseId("my-database")
249+
.setTransportOptions(GrpcTransportOptions.newBuilder().build())
250+
.build();
251+
```
252+
Setting the transport options explicitly to `GrpcTransportOptions` will signal the client to use gRPC instead of HTTP when making calls to the server.
253+
254+
To revert back to the existing stable behavior and transport, simply remove the transport options line or replace it with `HttpTransportOptions`. Please note this will require an application rebuild and restart.
255+
Example:
256+
```java
257+
// will default to existing HTTP transport behavior
258+
DatastoreOptions datastoreOptions = DatastoreOptions.newBuilder()
259+
.setProjectId("my-project")
260+
.setDatabaseId("my-database")
261+
.build();
262+
263+
// will also default to existing HTTP transport behavior
264+
DatastoreOptions datastoreOptions =
265+
DatastoreOptions.newBuilder()
266+
.setProjectId("my-project")
267+
.setDatabaseId("my-database")
268+
.setTransportOptions(HttpTransportOptions.newBuilder()
269+
.setConnectTimeout(1000)
270+
.build()).build();
271+
```
272+
273+
Note: client instantiations that already use `setTransportOptions` with `HttpTransportOptions` will continue to have the same behavior. Only transports that are explicitly set to gRPC will change.
274+
275+
#### Verify Datastore Transport Options Type
276+
To verify which type of TransportOptions you have successfully configured, you can use the below lines of code to compare transport options type:
277+
```java
278+
// checks if using gRPC transport options
279+
boolean isGRPC = datastore.getOptions().getTransportOptions() instanceof GrpcTransportOptions;
280+
281+
// checks if using HTTP transport options
282+
boolean isHTTP = datastore.getOptions().getTransportOptions() instanceof HTTPTransportOptions;
283+
```
284+
285+
#### New Features
286+
There are new gRPC specific features available to use in this update.
287+
288+
##### Channel Pooling
289+
To customize the number of channels your client uses, you can update the channel provider in the DatastoreOptions.
290+
See [ChannelPoolSettings](https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.grpc.ChannelPoolSettings) and [Performance Best Practices](https://grpc.io/docs/guides/performance/) for more information on channel pools and best practices for performance.
291+
292+
Example:
293+
```java
294+
InstantiatingGrpcChannelProvider channelProvider =
295+
DatastoreSettings.defaultGrpcTransportProviderBuilder()
296+
.setChannelPoolSettings(
297+
ChannelPoolSettings.builder()
298+
.setInitialChannelCount(MIN_VAL)
299+
.setMaxChannelCount(MAX_VAL)
300+
.build())
301+
.build();
302+
303+
DatastoreOptions options = DatastoreOptions.newBuilder()
304+
.setProjectId("my-project")
305+
.setChannelProvider(channelProvider)
306+
.setTransportOptions(GrpcTransportOptions.newBuilder().build())
307+
.build();
308+
```
213309
Testing
214310
-------
215311

0 commit comments

Comments
 (0)