11# Endpoints Getting Started with gRPC & Java Quickstart
22
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.
49
5101 . Build the code:
611
7- ```
12+ ``` bash
813 ./gradlew build
914 ```
1015
11161. Test running the code, optional:
1217
13- ```
18+ ` ` ` bash
1419 # In the background or another terminal run the server:
1520 java -jar server/build/libs/server.jar
1621
@@ -23,15 +28,15 @@ It is assumed that you have a working gRPC and Java environment.
2328
24291. Generate the ` out.pb` from the proto file.
2530
26- ```
31+ ` ` ` bash
2732 protoc --include_imports --include_source_info api/src/main/proto/helloworld.proto --descriptor_set_out out.pb
2833 ` ` `
2934
30351. Edit, ` api_config.yaml` . Replace ` MY_PROJECT_ID` with your project id.
3136
32371. Deploy your service config to Service Management:
3338
34- ```
39+ ` ` ` bash
3540 gcloud service-management deploy out.pb api_config.yaml
3641 # The Config ID should be printed out, looks like: 2017-02-01r0, remember this
3742
@@ -46,7 +51,7 @@ It is assumed that you have a working gRPC and Java environment.
4651
47521. Build a docker image for your gRPC server, store in your Registry
4853
49- ```
54+ ```bash
5055 gcloud container builds submit --tag gcr.io/${GCLOUD_PROJECT}/java-grpc-hello:1.0 .
5156 ```
5257
@@ -56,29 +61,29 @@ It is assumed that you have a working gRPC and Java environment.
5661
57621. Create your instance and ssh in.
5863
59- ```
64+ ```bash
6065 gcloud compute instances create grpc-host --image-family gci-stable --image-project google-containers --tags=http-server
6166 gcloud compute ssh grpc-host
6267 ```
6368
64691. Set some variables to make commands easier
6570
66- ```
71+ ```bash
6772 GCLOUD_PROJECT=$(curl -s "http://metadata.google.internal/computeMetadata/v1/project/project-id" -H "Metadata-Flavor: Google")
6873 SERVICE_NAME=hellogrpc.endpoints.${GCLOUD_PROJECT}.cloud.goog
6974 SERVICE_CONFIG_ID=<Your Config ID>
7075 ```
7176
72771. Pull your credentials to access Container Registry, and run your gRPC server container
7378
74- ```
79+ ```bash
7580 /usr/share/google/dockercfg_update.sh
7681 docker run -d --name=grpc-hello gcr.io/${GCLOUD_PROJECT}/java-grpc-hello:1.0
7782 ```
7883
79841. Run the Endpoints proxy
8085
81- ```
86+ ```bash
8287 docker run --detach --name=esp \
8388 -p 80:9000 \
8489 --link=grpc-hello:grpc-hello \
@@ -91,40 +96,40 @@ It is assumed that you have a working gRPC and Java environment.
9196
92971. Back on your local machine, get the external IP of your GCE instance.
9398
94- ```
99+ ```bash
95100 gcloud compute instances list
96101 ```
97102
981031. Run the client
99104
100- ```
105+ ```bash
101106 java -jar client/build/libs/client.jar --host <IP of GCE Instance>:80 --api_key <API Key from Console>
102107 ```
103108
104109### GKE
105110
1061111. Create a cluster
107112
108- ```
113+ ```bash
109114 gcloud container clusters create my-cluster
110115 ```
111116
1121171. Edit `container-engine.yaml`. Replace `SERVICE_NAME`, `SERVICE_CONFIG_ID`, and `GCLOUD_PROJECT` with your values.
113118
1141191. Deploy to GKE
115120
116- ```
121+ ```bash
117122 kubectl create -f ./container-engine.yaml
118123 ```
119124
1201251. Get IP of load balancer, run until you see an External IP.
121126
122- ```
127+ ```bash
123128 kubectl get svc grpc-hello
124129 ```
125130
1261311. Run the client
127132
128- ```
133+ ```bash
129134 java -jar client/build/libs/client.jar --host <IP of GKE LoadBalancer>:80 --api_key <API Key from Console>
130135 ```
0 commit comments