Need help with grpc-lb?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

liyue201
294 Stars 80 Forks 70 Commits 1 Opened issues

Description

gRPC service discovery and load balancing library for go

Services available

!
?

Need anything else?

Contributors list

# 139,609
Go
Shell
Jupyter...
HTML
53 commits
# 333,976
C
k8s
skywalk...
imagema...
2 commits
# 171,818
Node.js
chatbot
Telegra...
bot-fra...
1 commit

grpc-lb

This is a gRPC load balancing library for go.

Feature

  • supports Random, RoundRobin, LeastConnection and ConsistentHash strategies.
  • supports etcd,consul and zookeeper as a registry.

Example

package main

import ( etcd "github.com/coreos/etcd/client" "github.com/liyue201/grpc-lb/balancer" "github.com/liyue201/grpc-lb/examples/proto" registry "github.com/liyue201/grpc-lb/registry/etcd" "golang.org/x/net/context" "google.golang.org/grpc" "log" "time" )

func main() { etcdConfg := etcd.Config{ Endpoints: []string{"http://10.0.101.68:2379"}, } registry.RegisterResolver("etcd", etcdConfg, "/backend/services", "test", "1.0")

c, err := grpc.Dial("etcd:///", grpc.WithInsecure(), grpc.WithBalancerName(balancer.RoundRobin))
if err != nil {
    log.Printf("grpc dial: %s", err)
    return
}
defer c.Close()

client := proto.NewTestClient(c)
for i := 0; i < 500; i++ {

    resp, err := client.Say(context.Background(), &proto.SayReq{Content: "round robin"})
    if err != nil {
        log.Println(err)
        time.Sleep(time.Second)
        continue
    }
    time.Sleep(time.Second)
    log.Printf(resp.Content)
}

}

see more examples

Stargazers over time

Stargazers over time

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.