Codebase list golang-github-go-kit-kit / 9813199
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
1 changed file(s) with 34 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
00 # grpc
11
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.
55
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.
1018
1119 Next, get the protoc compiler.
12 Unfortunately, this needs to be done from source.
13 Fortunately, it's pretty straightforward.
1420
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
1630 brew install autoconf automake libtool
1731 git clone https://github.com/google/protobuf
1832 cd protobuf
2135
2236 Then, compile your service definition, from .proto to .go.
2337
24 ```
38 ```sh
2539 protoc add.proto --go_out=plugins=grpc:.
2640 ```
2741
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.
3147
3248 That's it!
3349 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.