go thrift

作者: 明明就_c565 | 来源:发表于2019-01-16 18:40 被阅读0次

server端

type Handle struct {

    com.Dial

}

/*

func Dial_server_start() {

    transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())

    protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()

    serverTransport, err := thrift.NewTServerSocket(common.NetworkAddr)

    if err != nil {

        glog.Println("Error!", err)

        os.Exit(1)

    }

    processor := com.NewDialProcessor(Handler)

    server := thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)

    glog.Println("thrift server in", common.NetworkAddr)

    server.Serve()

}

*/

func Dial_server_start() {

    serverTransport, err := thrift.NewTServerSocket(common.DialAddr)

    if err != nil {

        glog.Println("Error!", err)

        os.Exit(1)

    } 

    processor := com.NewDialProcessor(Handle{})

    server := thrift.NewTSimpleServer2(processor, serverTransport)

    glog.Println("Dial thrift server in", common.DialAddr)

    server.Serve()

}

client端

func Register() {

    var err error

    Transport, err = thrift.NewTSocket(net.JoinHostPort(common.AgentIp, strconv.Itoa(common.AgentPort)))

    if err != nil {

        glog.Println(os.Stderr, "error resolving address:", err)

        os.Exit(1)

    } 

    ProtocolFactory = thrift.NewTBinaryProtocolFactoryDefault()

    RegisterClient = com.NewAgentClientFactory(Transport, ProtocolFactory)

    ReportClient = com.NewAnalysisClientFactory(Transport, ProtocolFactory)

    if err := Transport.Open(); err != nil {

        glog.Println(os.Stderr, "Error opening socket", err)

        os.Exit(1)

    } 

    //defer Transport.Close()

}

相关文章

网友评论

      本文标题:go thrift

      本文链接:https://www.haomeiwen.com/subject/tpfvdqtx.html