...

Text file src/github.com/go-kit/kit/transport/grpc/README.md

Documentation: github.com/go-kit/kit/transport/grpc

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

View as plain text