ATC:go Thrift RPC 사용(연결 풀)
2367 단어 golangGolang 공부 방
RPC 엔진 은 현재 Thrift(client&serve)를 지원 합 니 다.
Thrift 설치
go get github.com/adolphlxm/atc/rpc/thrift
Thrift 서버 사용 절차
STEP 1:가방 도입
import(
"github.com/adolphlxm/atc/rpc/thrift"
)
두 번 째 단계:서비스 초기 화
//
ThriftRPC := thrift.NewThriftServe(`{"addr":"127.0.0,1:9090"}`)
// DEBUG
ThriftRPC.Debug(true)
// 、
ThriftRPC.Factory("binary", "framed")
//
ThriftRPC.Timeout(10)
STEP 3:서비스 시작
ThriftRPC.Run()
4 단계:논리 설정 에 따라 부 드 럽 게 종료
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)
}
atc-tool
도 구 를 사용 하 십시오.(그렇지 않 으 면 오류 가 발생 할 수 있 습 니 다.)$ atc-tool thrift [options] file
구체 적 인 thrift 명령 사용 가능
thrift --help
atc-tool 도구 보기예:
$ atc-tool thrift -r --gen go xxx.thrift
Thrift 클 라 이언 트 사용 절차
STEP 1:가방 도입
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")
STEP 3:사용 시작
//
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 데모:ATC-demo
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
set containerThere is no built-in set container in Go How to implement Set struct{} => type struct{}{} => 0bytes How to create set :=...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.