ATC:go Thrift RPC 사용(연결 풀)

RPC
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)
}
  • Go 의 Thrift 패 키 지 는 ATC 프레임 워 크 에 통합 되 었 습 니 다.다시 설치 하고 다운로드 할 필요 가 없습니다!
  • .thrift IDL 생 성 을 사용 합 니 다.goatc-tool도 구 를 사용 하 십시오.(그렇지 않 으 면 오류 가 발생 할 수 있 습 니 다.)
  • thrift 명령 행 도구,thrift IDL.go 파일 생산 에 사용
    $ atc-tool thrift [options] file
    

    구체 적 인 thrift 명령 사용 가능thrift --helpatc-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

    좋은 웹페이지 즐겨찾기