当前位置: 首页 > Linux

golang通用连接池,支持GRPC、RPC、TCP

时间:2023-04-06 01:41:42 Linux

poolhttps://github.com/flyaways/poolPool用于管理客户端和服务集群之间的连接。Pool的主要功能:通用连接池——PoolforGRPC,RPC,TCP。支持RPC超时。支持集群-连接到集群。动态更新-动态更新目标。Pool在Linux、MacOSX和Windows上运行。声明:目前采用随机数策略实现动态负载均衡。下载goget-ugopkg.in/flyaways/pool.v1导入方法import"gopkg.in/flyaways/pool.v1"示例包mainimport("log""time""gopkg.in/flyaways/pool.v1""google.golang.org/grpc")funcmain(){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())iferr!=nil{log.Printf("%#v\n",err)return}ifp==nil{log.Printf("p=%#v\n",p)return}deferp.Close()//动态更新服务位置//options.Input()<-&[]string{}conn,err:=p.Get()iferr!=nil{log.Printf("%#v\n",err)return}deferp。Put(conn)//实现各种业务代码//conn.DoSomething()//打印空闲连接数log.Printf("len=%d\n",p.IdleCount())}参考https:///github.com/fatih/poolhttps://github.com/silenceper/poolhttps://github.com/daizuozhuo/rpc-example版权声明麻省理工学院许可证(MIT)-请参阅LICENSE了解更多详情

最新推荐
猜你喜欢