grpclb

package module
v0.5.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 3, 2019 License: Apache-2.0 Imports: 11 Imported by: 0

README

grpclb

Build Status GoDoc Gem Version License

External Load Balancing Service solution for gRPC written in Go. The approach follows the proposal outlined by the core gRPC team.

grpclb load-balancer provides a neutral API which can be integrated with various service discovery frameworks. An example service discovery implementation is provided for Consul.

Usage

Load Balancer

Please also see the bootstrap for Consul backed load-balancers as a reference for building load balancers. Either use the command directly or build your very own.

Server

Servers can optionally report load to the Load Balancer. An example:

See Documentation

Client

See Documentation

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewResolver

func NewResolver(opt *Options) naming.Resolver

NewResolver creates a naming resolver

Example
const target = "helloworld"

// Create a round-robin load-balancer
balancer := grpc.RoundRobin(NewResolver(&Options{
	Address: "127.0.0.1:8383",
}))

// Set up a load-balanced connection to the server.
conn, err := grpc.Dial(target, grpc.WithInsecure(), grpc.WithBalancer(balancer))
if err != nil {
	log.Fatalf("did not connect: %v", err)
}
defer conn.Close()

c := pb.NewGreeterClient(conn)
r, err := c.SayHello(context.Background(), &pb.HelloRequest{Name: "world"})
if err != nil {
	log.Fatalf("could not greet: %v", err)
}
log.Printf("Greeting: %s", r.Message)
Output:

func PickFirst

func PickFirst(opt *Options) grpc.Balancer

PickFirst returns a Balancer that always selects the first address returned from the Resolver

Example
const target = "helloworld"

// Create a pick-first load-balancer
balancer := PickFirst(&Options{
	Address: "127.0.0.1:8383",
})

// Set up a load-balanced connection to the server.
conn, err := grpc.Dial(target, grpc.WithInsecure(), grpc.WithBalancer(balancer))
if err != nil {
	log.Fatalf("did not connect: %v", err)
}
defer conn.Close()

c := pb.NewGreeterClient(conn)
r, err := c.SayHello(context.Background(), &pb.HelloRequest{Name: "world"})
if err != nil {
	log.Fatalf("could not greet: %v", err)
}
log.Printf("Greeting: %s", r.Message)
Output:

Types

type Options

type Options struct {
	// Address is the address of the load balancer.
	// Default: 127.0.0.1:8383
	Address string
	// DialOptions define custom dial options.
	// Default: [WithInsecure].
	DialOptions []grpc.DialOption
	// UpdateInterval is the query interval for
	// updating known servers.
	// Default: 2s
	UpdateInterval time.Duration
}

Options is the picker configuration

Directories

Path Synopsis
cmd
discovery
consul
Package consul implements grpclb service discovery via Consul (consul.io).
Package consul implements grpclb service discovery via Consul (consul.io).
Package grpclb_backend_v1 is a generated protocol buffer package.
Package grpclb_backend_v1 is a generated protocol buffer package.
Package grpclb_balancer_v1 is a generated protocol buffer package.
Package grpclb_balancer_v1 is a generated protocol buffer package.
Package load include helpers for building grpclb compatible servers.
Package load include helpers for building grpclb compatible servers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL