Skip to content

Commit 2e3d5d0

Browse files
authored
Update README.md
1 parent be2a8f8 commit 2e3d5d0

File tree

1 file changed

+64
-12
lines changed

1 file changed

+64
-12
lines changed

README.md

Lines changed: 64 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,82 @@
11
# grpc_gateway_demo
22

3-
```shell
4-
$ curl localhost:8080/get -4 -X POST -H "Content-Type:application/json" -d '{"filename": "testdata/big.wav"}' -v > test_chunk_big.wav
5-
Note: Unnecessary use of -X or --request, POST is already inferred.
3+
This repository is used to show the gRPC-JSON transcoder in grap-gateway(https://github.com/grpc-ecosystem/grpc-gateway) can be used together with stream google.api.HttpBody to support streaming media transfer. For example, in the scenario of text-to-speech, it's useful to synthesize speech with streaming mode to reduce latency. This demo also shows how we can automatically transcode streaming grpc to chunked http response.
4+
5+
## Quick Start Guide
6+
7+
Clone the repository and dependencies:
8+
```sh
9+
git clone https://github.com/npuichigo/grpc_gateway_demo.git
10+
cd grpc_gateway_demo
11+
# Pull the dependent third_party repositories (if exists)
12+
git submodule update --init
13+
```
14+
15+
From the repo directory, test your service with docker-compose:
16+
```sh
17+
docker-compose pull
18+
docker-compose up
19+
```
20+
21+
Or you can rebuild the images with:
22+
23+
```sh
24+
$ docker-compose build
25+
```
26+
27+
Test restful api with curl:
28+
29+
```sh
30+
$ curl localhost:8080/get?filename=testdata/music.mp3 -4 -v > test_chunk_music.mp3
631
% Total % Received % Xferd Average Speed Time Time Time Current
732
Dload Upload Total Spent Left Speed
833
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 127.0.0.1...
934
* Connected to localhost (127.0.0.1) port 8080 (#0)
10-
> POST /get HTTP/1.1
35+
> GET /get?filename=testdata/music.mp3 HTTP/1.1
1136
> Host: localhost:8080
1237
> User-Agent: curl/7.47.0
1338
> Accept: */*
14-
> Content-Type:application/json
15-
> Content-Length: 32
1639
>
17-
} [32 bytes data]
18-
* upload completely sent off: 32 out of 32 bytes
1940
< HTTP/1.1 200 OK
20-
< Content-Type: audio/wav
41+
< Content-Type: audio/mp3
2142
< Grpc-Metadata-Accept-Encoding: identity,gzip
2243
< Grpc-Metadata-Content-Type: application/grpc
2344
< Grpc-Metadata-Grpc-Accept-Encoding: identity,deflate,gzip
24-
< Date: Mon, 25 Nov 2019 13:42:58 GMT
45+
< Date: Wed, 27 Nov 2019 03:28:40 GMT
2546
< Transfer-Encoding: chunked
2647
<
2748
{ [3836 bytes data]
28-
100 1137k 0 1137k 100 32 64627 1 0:00:32 0:00:18 0:00:14 58610
29-
* Connection #0 to host localhost left intact
3049
```
50+
51+
The grpc-server will send chunk of streaming data and the grpc-gateway will transcode that to chunked http response.
52+
```sh
53+
$ docker-compose up
54+
WARNING: Some services (grpc-server) use the 'deploy' key, which will be ignored. Compose does not support 'deploy' configuration - use `docker stack deploy` to deploy to a swarm.
55+
Starting grpc_gateway_demo_grpc-server_1 ... done
56+
Starting grpc_gateway_demo_grpc-gateway_1 ... done
57+
Starting grpc_gateway_demo_nginx_1 ... done
58+
Attaching to grpc_gateway_demo_grpc-server_1, grpc_gateway_demo_grpc-gateway_1, grpc_gateway_demo_nginx_1
59+
grpc-server_1 | I1127 03:28:21.755975 1 server.cc:58] Running gRPC Server at 0.0.0.0:9090 ...
60+
grpc-server_1 | I1127 03:28:40.348382 9 demo_service_impl.cc:36] Get audio from grpc server: testdata/music.mp3
61+
grpc-server_1 | I1127 03:28:40.349026 9 demo_service_impl.cc:59] Send 65536 bytes
62+
grpc-server_1 | I1127 03:28:40.449465 9 demo_service_impl.cc:59] Send 65536 bytes
63+
grpc-server_1 | I1127 03:28:40.550000 9 demo_service_impl.cc:59] Send 65536 bytes
64+
```
65+
66+
You can now use your browser to play the streaming media.
67+
68+
## Test with grpc client
69+
70+
Just start with the docker image grpc-server:
71+
```sh
72+
docker run -it --name your_name npuichigo/grpc-server /bin/bash
73+
./build/bin/grpc_server
74+
```
75+
76+
Open another terminal to use the grpc client:
77+
```sh
78+
docker exec -it your_name /bin/bash
79+
./build/bin/grpc_test_client --filename testdata/music.mp3
80+
```
81+
82+

0 commit comments

Comments
 (0)