mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-11 04:25:59 +08:00
conn
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package zookeeper
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type RoundRobin struct {
|
||||
index int
|
||||
lock sync.Mutex
|
||||
}
|
||||
|
||||
func (r *RoundRobin) getConnBalance(conns []*grpc.ClientConn) (conn *grpc.ClientConn) {
|
||||
r.lock.Lock()
|
||||
defer r.lock.Unlock()
|
||||
if r.index < len(conns)-1 {
|
||||
r.index++
|
||||
} else {
|
||||
r.index = 0
|
||||
}
|
||||
return conns[r.index]
|
||||
}
|
||||
Reference in New Issue
Block a user