内容简介:https://github.com/flyaways/poolPool 用于管理客户端到服务集群之间的连接.Pool的主要功能:
pool
https://github.com/flyaways/pool
Pool 用于管理客户端到服务集群之间的连接.
Pool的主要功能:
-
通用连接池- Pool for GRPC,RPC,TCP.support RPC timeout.
-
支持集群- Connet to Cluster.
-
动态更新- Danamic update targets.
Pool runs on Linux, Mac OS X, and Windows.
声明:当前使用随机数策略达到动态负载均衡.
下载
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())
if err != nil {
log.Printf("%#v\n", err)
return
}
if p == nil {
log.Printf("p= %#v\n", p)
return
}
defer p.Close()
//动态更新服务地址
//options.Input()<-&[]string{}
conn, err := p.Get()
if err != nil {
log.Printf("%#v\n", err)
return
}
defer p.Put(conn)
//实现各种业务代码
//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
版权声明
- The MIT License (MIT) - see LICENSE for more details
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- golang实现基于channel的通用连接池详解
- .net 多种关系型数据库通用连接池升级
- SOFAMesh中的多协议通用解决方案X-protocol介绍系列(1)——DNS通用寻址方案
- CCM通用计算工具
- 通用xxe检测方法
- C#抽象通用方法
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Learn Python the Hard Way
Zed Shaw / Example Product Manufacturer / 2011
This is a very beginner book for people who want to learn to code. If you can already code then the book will probably drive you insane. It's intended for people who have no coding chops to build up t......一起来看看 《Learn Python the Hard Way》 这本书的介绍吧!
RGB转16进制工具
RGB HEX 互转工具
Base64 编码/解码
Base64 编码/解码