A micro gRPC framework. A simplified experience for building gRPC services.

Overview

Go gRPC makes use of go-micro plugins to create a simpler framework for gRPC development. It interoperates with standard gRPC services seamlessly, including the grpc-gateway. The go-grpc library uses the go-micro client and server plugins which make use of github.com/grpc/grpc-go. This means we ignore the go-micro codec and transport but you get a native grpc experience.

Examples

Find an example greeter service in examples/greeter.

Getting Started

Install Protobuf

Protobuf is required for code generation

You’ll need to install:

Service Discovery

Service discovery is used to resolve service names to addresses.

Consul

Consul is used as the default service discovery system. See the install guide.

Discovery is pluggable. Find plugins for etcd, kubernetes, zookeeper and more in the micro/go-plugins repo.

mDNS

Multicast DNS is a built in alternative for zero dependencies.

Pass --registry=mdns to any command or the enviroment variable MICRO_REGISTRY=mdns

MICRO_REGISTRY=mdns go run main.go

Writing a Service

Go-grpc service is identical to a go-micro service. Which means you can swap out micro.NewService for grpc.NewService with zero other code changes.

package main

import (
	"context"
	"time"

	"github.com/micro/go-grpc"
	"github.com/micro/go-micro"
	hello "github.com/micro/go-grpc/examples/greeter/server/proto/hello"
)

type Say struct{}

func (s *Say) Hello(ctx context.Context, req *hello.Request, rsp *hello.Response) error {
	rsp.Msg = "Hello " + req.Name
	return nil
}

func main() {
	service := grpc.NewService(
		micro.Name("greeter"),
	)

	service.Init()

	hello.RegisterSayHandler(service.Server(), new(Say))

	if err := service.Run(); err != nil {
		log.Fatal(err)
	}
}

Use with Micro

You may want to use the micro toolkit with grpc services. To do this either use the prebuilt toolkit or simply include the grpc client plugin and rebuild the toolkit.

Go Get

go get github.com/micro/go-grpc/cmd/micro

Build Yourself

go get github.com/micro/micro

Create a plugins.go file

package main

import _ "github.com/micro/go-plugins/client/grpc"
import _ "github.com/micro/go-plugins/server/grpc"

Build binary

// For local use
go build -i -o micro ./main.go ./plugins.go

Flag usage of plugins

micro --client=grpc --server=grpc

Use with gRPC Gateway

Go-grpc seamlessly integrates with the gRPC ecosystem. This means the grpc-gateway can be used as per usual.

Find an example greeter api at examples/grpc/gateway.