ATC:go Thrift RPC 使用 (连接池)
来源:互联网 发布:javascript字符串替换 编辑:程序博客网 时间:2024/05/19 18:46
RPC
RPC引擎目前支持Thrift(client & serve)
Thrift安装
go get github.com/adolphlxm/atc/rpc/thrift
Thrift服务端使用步骤
第一步:引入包
import( "github.com/adolphlxm/atc/rpc/thrift")
第二步:初始化服务
// 创建服务实例ThriftRPC := thrift.NewThriftServe(`{"addr":"127.0.0,1:9090"}`)// DEBUGThriftRPC.Debug(true)// 设置传输层、协议层ThriftRPC.Factory("binary", "framed")// 设置超时时间ThriftRPC.Timeout(10)
第三步:启动服务
ThriftRPC.Run()
第四步:根据逻辑设置平滑退出
ctx, _ := context.WithTimeout(context.Background(), time.Duration(Aconfig.ThriftQTimeout)*time.Second)ThriftRPC.Shutdown(ctx)
开始使用
Thrift RPC 路由 router.go
func init() { processor := micro.NewMicroThriftProcessor(&MicroHandler{}) atc.ThriftRPC.RegisterProcessor("user", processor)}
- Go的Thrift包已经整合在ATC框架内了,无需重新安装和下载了!
- 使用.thrift IDL 生成 .go 请使用
atc-tool
工具(不然可能会报错.)
thrift命令行工具,用于 thrift IDL .go 文件生产
$ atc-tool thrift [options] file
具体thrift命令可使用 thrift --help
查看
atc-tool 工具
举例:
$ atc-tool thrift -r --gen go xxx.thrift
Thrift客户端使用步骤
第一步:引入包
import( "github.com/adolphlxm/atc/rpc/thrift")
第二步:初始化客户端连接池(由于thrift client 是非线程安全,So 提供了一个连接池管理)
pool := NewThriftPool(net.JoinHostPort("127.0.0.1", "9090"),10,10,10)pool.SetFactory("binary", "framed")
第三步:开始使用
// 获取一个可用连接conn,err := pool.Get()if err != nil { return err}mulProtocol := conn.NewTmultiplexedProtocol("user")// 这部分调用自动生成代码client := micro.NewMicroThriftClientProtocol(conn.GetTtransport(), conn.GetTprotocol(), mulProtocol)
LICENSE
ATC is Licensed under the Apache License, Version 2.0 (the “License”)
(http://www.apache.org/licenses/LICENSE-2.0.html).
GITHUB源码下载
框架:ATC
工具: ATC-tool
DEMO: ATC-demo
阅读全文
0 0
- ATC:go Thrift RPC 使用 (连接池)
- ATC:go logs 使用
- 使用Thrift RPC编写程序
- 使用Thrift RPC编写程序
- 使用Thrift RPC编写程序
- 使用Thrift RPC编写程序
- 使用Thrift RPC编写程序
- 使用Thrift RPC编写程序
- 使用Thrift RPC编写程序
- 使用Thrift RPC编写程序
- 使用Thrift RPC编写程序
- 使用Thrift RPC编写程序
- 使用Thrift RPC编写程序
- RPC框架-Thrift的使用
- 使用Thrift RPC编写程序
- Thrift使用入门-RPC服务
- RPC框架Thrift (C++和GO语言例子)
- Thrift RPC
- android 蓝牙BLE 开发
- elasticsearch学习笔记-安装与配置
- 《stl源码剖析》学习笔记 1.vector
- android studio internet连接本地服务器错误1
- 登陆oracle的三种方法
- ATC:go Thrift RPC 使用 (连接池)
- win7系统搭建PHP+Mysql+Apache环境+部署ecshop项目
- CDH遇到问题点滴记录
- 第二章 创建对话框
- Tensorflow之Basic word2vec代码详解(上)
- 如何查与给定时间最接近的一条信息
- 这可能是最好的性能优化教程(三)
- 菜鸟学习笔记--Mysql性能优化
- spring-mvc传到controller乱码问题