Built motion from commit 6a09e18b.|2.6.11
[motion2.git] / legacy-libs / grpc-gcp / README.md
1 # gRPC-GCP for Node.js
2
3 A Node.js module providing grpc supports for Google Cloud APIs.
4
5 ## Installation
6
7 ```sh
8 npm install grpc-gcp --save
9 ```
10
11 ## Usage
12
13 Let's use Spanner API as an example.
14
15 First, Create a json file defining API configuration, with ChannelPoolConfig and MethodConfig.
16
17 ```json
18 {
19   "channelPool": {
20     "maxSize": 10,
21     "maxConcurrentStreamsLowWatermark": 1
22   },
23   "method": [
24     {
25       "name": [ "/google.spanner.v1.Spanner/CreateSession" ],
26       "affinity": {
27         "command": "BIND",
28         "affinityKey": "name"
29       }
30     },
31     {
32       "name": [ "/google.spanner.v1.Spanner/GetSession" ],
33       "affinity": {
34         "command": "BOUND",
35         "affinityKey": "name"
36       }
37     },
38     {
39       "name": [ "/google.spanner.v1.Spanner/DeleteSession" ],
40       "affinity": {
41         "command": "UNBIND",
42         "affinityKey": "name"
43       }
44     }
45   ]
46 }
47 ```
48
49 Load configuration to ApiConfig.
50
51 ```javascript
52 var grpcGcp = require('grpc-gcp');
53 var fs = require('fs');
54
55 var apiDefinition = JSON.parse(fs.readFileSync('your_api_config_json_file'));
56 var apiConfig = grpcGcp.createGcpApiConfig(apiDefinition);
57 ```
58
59 Pass `gcpChannelFactoryOverride` and `gcpCallInvocationTransformer` to channel options when initializing api client.
60
61 ```javascript
62 var channelOptions = {
63   channelFactoryOverride: grpcGcp.gcpChannelFactoryOverride,
64   callInvocationTransformer: grpcGcp.gcpCallInvocationTransformer,
65   gcpApiConfig: apiConfig,
66 };
67
68 var client = new SpannerClient(
69   'spanner.googleapis.com:443',
70   channelCreds,
71   channelOptions
72 );
73 ```
74
75 ## Build from source
76
77 Download source.
78
79 ```sh
80 git clone https://github.com/GoogleCloudPlatform/grpc-gcp-node.git && cd grpc-gcp-node
81 ```
82
83 ```sh
84 git submodule update --init --recursive
85 ```
86
87 Install dependencies and build from source.
88
89 ```sh
90 npm install
91 ```
92
93 ```sh
94 npm run build
95 ```
96
97 ## Test
98
99 Setup credentials. See [Getting Started With Authentication](https://cloud.google.com/docs/authentication/getting-started) for more details.
100
101 ```sh
102 export GOOGLE_APPLICATION_CREDENTIALS=path/to/key.json
103 ```
104
105 Run unit tests.
106
107 ```sh
108 npm run unit-tests
109 ```
110
111 Run integration tests.
112
113 ```sh
114 npm run integration-tests
115 ```