balancer

package module
v0.0.0-...-2e54b7d Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2018 License: MIT Imports: 8 Imported by: 0

README

Client-side dynamic load balancer for the GRPC

Go Report Card Build Status codecov

This library support new grpc-go/balancer interface. You can pass self-implemented endpoint providers. For this you can realize service interface and pass implementation to the .NewBalancerBuilder constructor. This library support consul by default.

Example

package api // which contains code generated from the proto-files

import (
	"github.com/mbobakov/grpc-dynamic-balancer"
	"github.com/mbobakov/grpc-dynamic-balancer/provider/consul"
	"google.golang.org/grpc"
	grpcbalancer "google.golang.org/grpc/balancer"
)

func NewLoadBalancedClient(consulAddr, serviceName string, opts ...grpc.DialOption) (<Client>, error) {
	bb := balancer.NewBalancerBuilder(serviceName, &consul.Consul{})
	grpcbalancer.Register(bb)
	opts = append(opts, grpc.WithBalancerName(serviceName))
	conn, err := grpc.Dial(consulAddr, opts...)
	if err != nil { <handle error> }
	return &grpcGeneratedClient{cc: conn}, nil
}

Motivation

After some test load-balancing on the client-side is the most efficient way to HA. Tests(envoy,nginx) TBD

Contributing

Feel free to open issues, PRs and refer to the implementation of endpoints providers

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewBalancerBuilder

func NewBalancerBuilder(name string, provider service) balancer.Builder

NewBalancerBuilder returns a balancer builder. The balancers built by this builder will use the picker builder to build pickers.

Types

This section is empty.

Directories

Path Synopsis
provider

Jump to

Keyboard shortcuts

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