1
1
# Endpoints Getting Started with gRPC & Java Quickstart
2
2
3
- It is assumed that you have a working gRPC and Java environment.
3
+ It is assumed that you have a
4
+ working
5
+ [ gRPC] ( http://www.grpc.io/docs/ ) ,
6
+ [ ProtoBuf] ( https://github.com/google/protobuf#protocol-compiler-installation ) and
7
+ Java environment, a Google Cloud account
8
+ and [ SDK] ( https://cloud.google.com/sdk/ ) configured.
4
9
5
10
1 . Build the code:
6
11
7
- ```
12
+ ``` bash
8
13
./gradlew build
9
14
```
10
15
11
16
1. Test running the code, optional:
12
17
13
- ```
18
+ ` ` ` bash
14
19
# In the background or another terminal run the server:
15
20
java -jar server/build/libs/server.jar
16
21
@@ -23,15 +28,15 @@ It is assumed that you have a working gRPC and Java environment.
23
28
24
29
1. Generate the ` out.pb` from the proto file.
25
30
26
- ```
31
+ ` ` ` bash
27
32
protoc --include_imports --include_source_info api/src/main/proto/helloworld.proto --descriptor_set_out out.pb
28
33
` ` `
29
34
30
35
1. Edit, ` api_config.yaml` . Replace ` MY_PROJECT_ID` with your project id.
31
36
32
37
1. Deploy your service config to Service Management:
33
38
34
- ```
39
+ ` ` ` bash
35
40
gcloud service-management deploy out.pb api_config.yaml
36
41
# The Config ID should be printed out, looks like: 2017-02-01r0, remember this
37
42
@@ -46,7 +51,7 @@ It is assumed that you have a working gRPC and Java environment.
46
51
47
52
1. Build a docker image for your gRPC server, store in your Registry
48
53
49
- ```
54
+ ```bash
50
55
gcloud container builds submit --tag gcr.io/${GCLOUD_PROJECT}/java-grpc-hello:1.0 .
51
56
```
52
57
@@ -56,29 +61,29 @@ It is assumed that you have a working gRPC and Java environment.
56
61
57
62
1. Create your instance and ssh in.
58
63
59
- ```
64
+ ```bash
60
65
gcloud compute instances create grpc-host --image-family gci-stable --image-project google-containers --tags=http-server
61
66
gcloud compute ssh grpc-host
62
67
```
63
68
64
69
1. Set some variables to make commands easier
65
70
66
- ```
71
+ ```bash
67
72
GCLOUD_PROJECT=$(curl -s "http://metadata.google.internal/computeMetadata/v1/project/project-id" -H "Metadata-Flavor: Google")
68
73
SERVICE_NAME=hellogrpc.endpoints.${GCLOUD_PROJECT}.cloud.goog
69
74
SERVICE_CONFIG_ID=<Your Config ID>
70
75
```
71
76
72
77
1. Pull your credentials to access Container Registry, and run your gRPC server container
73
78
74
- ```
79
+ ```bash
75
80
/usr/share/google/dockercfg_update.sh
76
81
docker run -d --name=grpc-hello gcr.io/${GCLOUD_PROJECT}/java-grpc-hello:1.0
77
82
```
78
83
79
84
1. Run the Endpoints proxy
80
85
81
- ```
86
+ ```bash
82
87
docker run --detach --name=esp \
83
88
-p 80:9000 \
84
89
--link=grpc-hello:grpc-hello \
@@ -91,40 +96,40 @@ It is assumed that you have a working gRPC and Java environment.
91
96
92
97
1. Back on your local machine, get the external IP of your GCE instance.
93
98
94
- ```
99
+ ```bash
95
100
gcloud compute instances list
96
101
```
97
102
98
103
1. Run the client
99
104
100
- ```
105
+ ```bash
101
106
java -jar client/build/libs/client.jar --host <IP of GCE Instance>:80 --api_key <API Key from Console>
102
107
```
103
108
104
109
### GKE
105
110
106
111
1. Create a cluster
107
112
108
- ```
113
+ ```bash
109
114
gcloud container clusters create my-cluster
110
115
```
111
116
112
117
1. Edit `container-engine.yaml`. Replace `SERVICE_NAME`, `SERVICE_CONFIG_ID`, and `GCLOUD_PROJECT` with your values.
113
118
114
119
1. Deploy to GKE
115
120
116
- ```
121
+ ```bash
117
122
kubectl create -f ./container-engine.yaml
118
123
```
119
124
120
125
1. Get IP of load balancer, run until you see an External IP.
121
126
122
- ```
127
+ ```bash
123
128
kubectl get svc grpc-hello
124
129
```
125
130
126
131
1. Run the client
127
132
128
- ```
133
+ ```bash
129
134
java -jar client/build/libs/client.jar --host <IP of GKE LoadBalancer>:80 --api_key <API Key from Console>
130
135
```
0 commit comments