本文整理汇总了Golang中git/apache/org/thrift/git/lib/go/thrift.TTransportFactory类的典型用法代码示例。如果您正苦于以下问题:Golang TTransportFactory类的具体用法?Golang TTransportFactory怎么用?Golang TTransportFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TTransportFactory类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: runClient
func runClient(transportFactory thrift.TTransportFactory,
protocolFactory thrift.TProtocolFactory, addr string, secure bool) error {
opts := nats.DefaultOptions
opts.Servers = []string{addr}
opts.Secure = secure
conn, err := opts.Connect()
if err != nil {
return err
}
defer conn.Close()
transport, err := thrift_nats.NATSTransportFactory(conn, "foo", time.Second, time.Second)
if err != nil {
return err
}
transport = transportFactory.GetTransport(transport)
defer transport.Close()
if err := transport.Open(); err != nil {
return err
}
return handleClient(tutorial.NewCalculatorClientFactory(transport, protocolFactory))
}
开发者ID:Workiva,项目名称:thrift-nats,代码行数:25,代码来源:client.go
示例2: runClient
func runClient(transportFactory thrift.TTransportFactory, protocolFactory thrift.TProtocolFactory, addr string, secure bool) error {
var transport thrift.TTransport
var err error
if secure {
cfg := new(tls.Config)
cfg.InsecureSkipVerify = true
transport, err = thrift.NewTSSLSocket(addr, cfg)
} else {
transport, err = thrift.NewTSocket(addr)
}
if err != nil {
fmt.Println("Error opening socket:", err)
return err
}
if transport == nil {
return fmt.Errorf("Error opening socket, got nil transport. Is server available?")
}
transport = transportFactory.GetTransport(transport)
if transport == nil {
return fmt.Errorf("Error from transportFactory.GetTransport(), got nil transport. Is server available?")
}
err = transport.Open()
if err != nil {
return err
}
defer transport.Close()
return handleClient(tutorial.NewCalculatorClientFactory(transport, protocolFactory))
}
开发者ID:glycerine,项目名称:golang-thrift-minimal-example,代码行数:30,代码来源:client.go
示例3: runClient
func runClient(transportFactory thrift.TTransportFactory, protocolFactory thrift.TProtocolFactory, addr string) error {
var transport thrift.TTransport
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
}
return handleClient(tutorial.NewCalculatorClientFactory(transport, protocolFactory))
}
开发者ID:Rheeseyb,项目名称:thrift,代码行数:14,代码来源:client.go
示例4: runClient
func runClient(transportFactory thrift.TTransportFactory, protocolFactory thrift.TProtocolFactory, addr string, secure bool) error {
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
}
return handleClient(awesome_service.NewAwesomeServiceClientFactory(transport, protocolFactory))
}
开发者ID:y-okubo,项目名称:thrift-test,代码行数:18,代码来源:main.go
示例5: NewThriftRequestExec
func NewThriftRequestExec(tFac thrift.TTransportFactory, clientExec ThriftClientExecutor, timeout time.Duration, hosts ...string) bender.RequestExecutor {
return func(_ int64, request interface{}) (interface{}, error) {
addr := hosts[rand.Intn(len(hosts))]
socket, err := thrift.NewTSocketTimeout(addr, timeout)
if err != nil {
return nil, err
}
defer socket.Close()
transport := tFac.GetTransport(socket)
if err := transport.Open(); err != nil {
return nil, err
}
defer transport.Close()
return clientExec(request, transport)
}
}
开发者ID:sabagostar-ex,项目名称:bender,代码行数:18,代码来源:thrift.go
示例6: Update
func Update(transportFactory thrift.TTransportFactory, protocolFactory thrift.TProtocolFactory, variable *person.Person) (*person.Person, error) {
socket, err := thrift.NewTSocket("localhost:4000")
if err != nil {
log.Println(err)
}
transport := transportFactory.GetTransport(socket)
client := person.NewPersonServiceClientFactory(transport, protocolFactory)
defer client.Transport.Close()
if err := client.Transport.Open(); err != nil {
log.Println(err)
}
result, err := client.Update(variable)
if err != nil {
log.Println(err)
return nil, err
}
return result, nil
}
开发者ID:dynastymasra,项目名称:GoGinThrift,代码行数:20,代码来源:person.go
示例7: Delete
func Delete(transportFactory thrift.TTransportFactory, protocolFactory thrift.TProtocolFactory, id int64) error {
socket, err := thrift.NewTSocket("localhost:4000")
if err != nil {
log.Println(err)
}
transport := transportFactory.GetTransport(socket)
client := person.NewPersonServiceClientFactory(transport, protocolFactory)
defer client.Transport.Close()
if err := client.Transport.Open(); err != nil {
log.Println(err)
}
err = client.Destroy(id)
if err != nil {
log.Println(err)
return err
}
return nil
}
开发者ID:dynastymasra,项目名称:GoGinThrift,代码行数:20,代码来源:person.go
示例8: RunClient
func RunClient(transportFactory thrift.TTransportFactory, protocolFactory thrift.TProtocolFactory, addr string, secure bool) error {
var transport thrift.TTransport
var err error
if secure {
cfg := new(tls.Config)
cfg.InsecureSkipVerify = true
transport, err = thrift.NewTSSLSocket(addr, cfg)
} else {
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
}
return HandleClient(addrservice.NewAddressServiceClientFactory(transport, protocolFactory))
}
开发者ID:zhaorui1,项目名称:thrift-rpc-framework,代码行数:21,代码来源:driver_test.go
示例9: RunThriftService
func RunThriftService(thriftFunc ThriftFunc) (map[string]string, error) {
//addr := flag.String("addr", "localhost:9090", "Address to listen to")
//secure := flag.Bool("secure", false, "Use tls secure transport")
//flag.Parse()
addr := "localhost:9090"
secure := true
var protocolFactory thrift.TProtocolFactory
protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
var transportFactory thrift.TTransportFactory
transportFactory = thrift.NewTTransportFactory()
var transport thrift.TTransport
var err error
if secure {
cfg := new(tls.Config)
cfg.InsecureSkipVerify = true
transport, err = thrift.NewTSSLSocket(addr, cfg)
} else {
transport, err = thrift.NewTSocket(addr)
}
if err != nil {
fmt.Println("Error opening socket:", err)
return nil, err
}
transport = transportFactory.GetTransport(transport)
defer transport.Close()
if err := transport.Open(); err != nil {
return nil, err
}
client := thriftlib.NewBaseServiceClientFactory(transport, protocolFactory)
return thriftFunc(client)
}
开发者ID:kevinhuo88888,项目名称:o3erp,代码行数:36,代码来源:thriftservice.go
示例10: testHappyPath
func testHappyPath(t *testing.T, proto thrift.TProtocolFactory, buffered, framed bool) {
options := nats.DefaultOptions
options.Servers = []string{fmt.Sprintf("nats://localhost:%d", port)}
serverConn, err := options.Connect()
if err != nil {
t.Fatal("Failed to connect to gnatsd", err)
}
defer serverConn.Close()
clientConn, err := options.Connect()
if err != nil {
t.Fatal("Failed to connect to gnatsd", err)
}
defer clientConn.Close()
var transportFactory thrift.TTransportFactory
if buffered {
transportFactory = thrift.NewTBufferedTransportFactory(8192)
} else {
transportFactory = thrift.NewTTransportFactory()
}
if framed {
transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
}
processor := tutorial.NewCalculatorProcessor(NewCalculatorHandler())
server := thrift_nats.NewNATSServer(serverConn, subject, -1, -1, processor,
transportFactory, proto)
wait := make(chan bool)
go func() {
wait <- true
if err := server.Serve(); err != nil {
t.Fatal("Failed to start thrift server", err)
}
}()
<-wait
defer server.Stop()
// Give the server a chance to start.
time.Sleep(500 * time.Millisecond)
transport, err := thrift_nats.NATSTransportFactory(clientConn, subject, time.Second, -1)
if err != nil {
t.Fatal("Failed to create NATS transport", err)
}
transport = transportFactory.GetTransport(transport)
if err := transport.Open(); err != nil {
t.Fatal("Failed to open transport", err)
}
defer transport.Close()
client := tutorial.NewCalculatorClientFactory(transport, proto)
if err := client.Ping(); err != nil {
t.Fatal("Ping failed", err)
}
if err := client.Zip(); err != nil {
t.Fatal("Zip failed", err)
}
sum, err := client.Add(1, 1)
if err != nil {
t.Fatal("Sum failed", err)
}
if sum != 2 {
t.Fatalf("Expected Sum result 2, got %d", sum)
}
work := tutorial.NewWork()
work.Op = tutorial.Operation_DIVIDE
work.Num1 = 8
work.Num2 = 4
quotient, err := client.Calculate(1, work)
if err != nil {
t.Fatal("Calculate failed", err)
}
if sum != 2 {
t.Fatalf("Expected Calculate result 4, got %d", quotient)
}
work.Op = tutorial.Operation_DIVIDE
work.Num1 = 1
work.Num2 = 0
_, err = client.Calculate(2, work)
switch v := err.(type) {
case *tutorial.InvalidOperation:
break
default:
t.Fatalf("Expected Calculate to return InvalidOperation, got %s", v)
}
log, err := client.GetStruct(1)
if err != nil {
t.Fatal("GetStruct failed", err)
}
if log.Value != "2" {
t.Fatalf("Expected struct value `2`, got `%s`", log.Value)
}
log, err = client.GetStruct(2)
if err != nil {
//.........这里部分代码省略.........
开发者ID:Workiva,项目名称:thrift-nats,代码行数:101,代码来源:thrift_nats_test.go
示例11: RunThrifter
func RunThrifter(index int, dataChan chan *demoThrift.RequestInfo) {
var err error = nil
var data *demoThrift.RequestInfo
for {
if err != nil { // wait for a while when retry
time.Sleep(time.Duration(30) * time.Second)
}
secure := false
protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
//transportFactory := thrift.NewTTransportFactory()
var transportFactory thrift.TTransportFactory
//transportFactory = thrift.NewTBufferedTransportFactory(8192)
transportFactory = thrift.NewTTransportFactory()
//transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
var transport thrift.TTransport
if secure {
cfg := new(tls.Config)
cfg.InsecureSkipVerify = true
transport, err = thrift.NewTSSLSocket(ThrifterAddr, cfg)
} else {
transport, err = thrift.NewTSocket(ThrifterAddr)
}
if err != nil {
Log.Error("[No.%d sender] Error opening socket: %s", index, err)
continue
}
transport = transportFactory.GetTransport(transport)
if err = transport.Open(); err != nil {
Log.Error("[No.%d sender] Error opening transport: %s", index, err)
continue
}
client := demoThrift.NewDemoThriftClientFactory(transport, protocolFactory)
if client == nil {
Log.Error("[No.%d sender] Error new unify-client", index)
transport.Close()
continue
}
Log.Info("[No.%d sender] connected to judge center", index)
// loop for sending
for {
if data == nil {
data = <-dataChan
}
//Log.Info("No.%d sender work!", index)
var result string
// retry times
for i := 0; i < 2; i++ {
result, err = client.SendtoParser(data)
if err != nil {
Log.Error("[No.%d sender] client.SendtoParser failed, result: %s, err: %s", index, result, err.Error())
time.Sleep(time.Duration(5) * time.Second)
continue
}
data = nil
Log.Info("[No.%d sender] get result: %s", index, result)
break
}
if err != nil {
// reconnect
transport.Close()
Log.Info("[No.%d sender] try to reconnect, err: %s", index, err.Error())
break
}
}
}
}
开发者ID:rocflyhi,项目名称:glow,代码行数:75,代码来源:thrifter.go
注:本文中的git/apache/org/thrift/git/lib/go/thrift.TTransportFactory类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论