thrift golang 多服务

服务端

processor := enameepp.NewEppContactProcessor(&EppStruct{})
domainProcessor := enameepp.NewEppDomainProcessor(&EppStructDomain{})
TMultiplexedProcessor := thrift.NewTMultiplexedProcessor()
TMultiplexedProcessor.RegisterProcessor("contact", processor)
TMultiplexedProcessor.RegisterProcessor("domain", domainProcessor)

server := thrift.NewTSimpleServer4(TMultiplexedProcessor, transport, transportFactory, protocolFactory)

fmt.Println("Starting the simple server... on ", addr)
return server.Serve()

客户端

var transport thrift.TTransport
var err error
transport, err = thrift.NewTSocket(addr)
if err != nil {
	fmt.Println("Error opening socket:", err)
	return err
}
transport = transportFactory.GetTransport(transport)
defer transport.Close()
if err := transport.Open(); err != nil {
	return err
}

protocol := thrift.NewTBinaryProtocolTransport(transport)
mp := thrift.NewTMultiplexedProtocol(protocol, "domain")

//client := enameepp.NewEppContactClientProtocol(transport, protocol, mp)
client := enameepp.NewEppDomainClientProtocol(transport, protocol, mp)
return handleClient2(client)

2 评论

发表评论

电子邮件地址不会被公开。 必填项已用*标注