Skip to content

mbobakov/grpc-dynamic-balancer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Client-side dynamic load balancer for the GRPC

Go Report Card License: MIT 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

About

use github.com/mbobakov/grpc-consul-resolver insteed

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages