Merge pull request #557 from Fanatics/update-grpc-transport-readme
update grpc readme information about protoc and streams
Peter Bourgon authored 6 years ago
GitHub committed 6 years ago
0 | 0 | # grpc |
1 | 1 | |
2 | [gRPC](http://www.grpc.io/) is an excellent, modern IDL and transport for microservices. | |
3 | If you're starting a greenfield project, Go kit strongly recommends gRPC as your default transport. | |
4 | And using gRPC and Go kit together is very simple. | |
2 | [gRPC](http://www.grpc.io/) is an excellent, modern IDL and transport for | |
3 | microservices. If you're starting a greenfield project, go-kit strongly | |
4 | recommends gRPC as your default transport. | |
5 | 5 | |
6 | First, define your service using protobuf3. | |
7 | This is explained [in gRPC documentation](http://www.grpc.io/docs/#defining-a-service). | |
8 | See [add.proto](https://github.com/go-kit/kit/blob/ec8b02591ee873433565a1ae9d317353412d1d27/examples/addsvc/pb/add.proto) for an example. | |
9 | Make sure the proto definition matches your service's Go kit (interface) definition. | |
6 | One important note is that while gRPC supports streaming requests and replies, | |
7 | go-kit does not. You can still use streams in your service, but their | |
8 | implementation will not be able to take advantage of many go-kit features like middleware. | |
9 | ||
10 | Using gRPC and go-kit together is very simple. | |
11 | ||
12 | First, define your service using protobuf3. This is explained | |
13 | [in gRPC documentation](http://www.grpc.io/docs/#defining-a-service). | |
14 | See | |
15 | [add.proto](https://github.com/go-kit/kit/blob/ec8b02591ee873433565a1ae9d317353412d1d27/examples/addsvc/pb/add.proto) | |
16 | for an example. Make sure the proto definition matches your service's go-kit | |
17 | (interface) definition. | |
10 | 18 | |
11 | 19 | Next, get the protoc compiler. |
12 | Unfortunately, this needs to be done from source. | |
13 | Fortunately, it's pretty straightforward. | |
14 | 20 | |
15 | ``` | |
21 | You can download pre-compiled binaries from the | |
22 | [protobuf release page](https://github.com/google/protobuf/releases). | |
23 | You will unzip a folder called `protoc3` with a subdirectory `bin` containing | |
24 | an executable. Move that executable somewhere in your `$PATH` and you're good | |
25 | to go! | |
26 | ||
27 | It can also be built from source. | |
28 | ||
29 | ```sh | |
16 | 30 | brew install autoconf automake libtool |
17 | 31 | git clone https://github.com/google/protobuf |
18 | 32 | cd protobuf |
21 | 35 | |
22 | 36 | Then, compile your service definition, from .proto to .go. |
23 | 37 | |
24 | ``` | |
38 | ```sh | |
25 | 39 | protoc add.proto --go_out=plugins=grpc:. |
26 | 40 | ``` |
27 | 41 | |
28 | Finally, write a tiny binding from your service definition to the gRPC definition. | |
29 | It's a simple conversion from one domain to another. | |
30 | See [grpc_binding.go](https://github.com/go-kit/kit/blob/ec8b02591ee873433565a1ae9d317353412d1d27/examples/addsvc/grpc_binding.go) for an example. | |
42 | Finally, write a tiny binding from your service definition to the gRPC | |
43 | definition. It's a simple conversion from one domain to another. | |
44 | See | |
45 | [grpc_binding.go](https://github.com/go-kit/kit/blob/ec8b02591ee873433565a1ae9d317353412d1d27/examples/addsvc/grpc_binding.go) | |
46 | for an example. | |
31 | 47 | |
32 | 48 | That's it! |
33 | 49 | The gRPC binding can be bound to a listener and serve normal gRPC requests. |
34 | And within your service, you can use standard Go kit components and idioms. | |
35 | See [addsvc](https://github.com/go-kit/kit/tree/master/examples/addsvc) for a complete working example with gRPC support. | |
36 | And remember: Go kit services can support multiple transports simultaneously. | |
50 | And within your service, you can use standard go-kit components and idioms. | |
51 | See [addsvc](https://github.com/go-kit/kit/tree/master/examples/addsvc) for | |
52 | a complete working example with gRPC support. And remember: go-kit services | |
53 | can support multiple transports simultaneously. |