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