Pool is Used to manage and reuse client connections to service cluster.
Pool provides several key features:
-
General Purpose - Pool for GRPC,RPC,TCP.support RPC timeout.
-
Support Cluster - Connet to Cluster.
-
Danamic Update - Danamic update targets.
Pool runs on Linux, Mac OS X, and Windows.
Note: Random to pick a target to get one connection for loadbalance.
go get -u gopkg.in/flyaways/pool.v1
import "gopkg.in/flyaways/pool.v1"
package main
import (
"log"
"time"
"gopkg.in/flyaways/pool.v1"
"google.golang.org/grpc"
)
func main() {
options := &pool.Options{
InitTargets: []string{"127.0.0.1:8080"},
InitCap: 5,
MaxCap: 30,
DialTimeout: time.Second * 5,
IdleTimeout: time.Second * 60,
ReadTimeout: time.Second * 5,
WriteTimeout: time.Second * 5,
}
p, err := pool.NewGRPCPool(options, grpc.WithInsecure())//for grpc
//p, err := pool.NewRPCPool(options) //for rpc
//p, err := pool.NewTCPPool(options) //for tcp
if err != nil {
log.Printf("%#v\n", err)
return
}
if p == nil {
log.Printf("p= %#v\n", p)
return
}
defer p.Close()
//todo
//danamic update targets
//options.Input()<-&[]string{}
conn, err := p.Get()
if err != nil {
log.Printf("%#v\n", err)
return
}
defer p.Put(conn)
//todo
//conn.DoSomething()
log.Printf("len=%d\n", p.IdleCount())
}
- https://github.com/fatih/pool
- https://github.com/silenceper/pool
- https://github.com/daizuozhuo/rpc-example
Contributors
- The MIT License (MIT) - see LICENSE for more details