本文整理匯總了Golang中github.com/apache/thrift/lib/go/thrift.NewTBufferedTransportFactory函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewTBufferedTransportFactory函數的具體用法?Golang NewTBufferedTransportFactory怎麽用?Golang NewTBufferedTransportFactory使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewTBufferedTransportFactory函數的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Start
func (s *ThriftServer) Start() (err error) {
processor := wire.NewBarProcessor(s.Handler)
var transport t_thrift.TServerTransport
if transport, err = t_thrift.NewTServerSocket(s.options.Bind); err != nil {
return
}
protoFactory := t_thrift.NewTBinaryProtocolFactoryDefault()
transportFactory := t_thrift.NewTBufferedTransportFactory(
s.BufferSize)
s.TServer = t_thrift.NewTSimpleServer4(processor, transport,
transportFactory, protoFactory)
logx.Debugf("thrift listening at %s", s.options.Info.RPCEndpoints[0])
errChan := make(chan error, 1)
go func() {
errChan <- s.TServer.Serve()
}()
defer s.TServer.Stop()
defer s.cancel()
select {
case <-s.ctx.Done():
return
case err = <-errChan:
return
}
return
}
示例2: New
// New returns a stateful factory for Sum and Concat Endpoints
func New(protocol string, bufferSize int, framed bool, logger log.Logger) client {
var protocolFactory thrift.TProtocolFactory
switch protocol {
case "compact":
protocolFactory = thrift.NewTCompactProtocolFactory()
case "simplejson":
protocolFactory = thrift.NewTSimpleJSONProtocolFactory()
case "json":
protocolFactory = thrift.NewTJSONProtocolFactory()
case "binary", "":
protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
default:
panic("invalid protocol")
}
var transportFactory thrift.TTransportFactory
if bufferSize > 0 {
transportFactory = thrift.NewTBufferedTransportFactory(bufferSize)
} else {
transportFactory = thrift.NewTTransportFactory()
}
if framed {
transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
}
return client{transportFactory, protocolFactory, logger}
}
示例3: NewTPool
func NewTPool(endpoints []string, bufferSize int, n int, ttl time.Duration) (res *TPool) {
res = &TPool{
endpoints: endpoints,
endpointsCap: len(endpoints) - 1,
ttl: ttl,
transportFactory: thrift.NewTBufferedTransportFactory(bufferSize),
protoFactory: thrift.NewTBinaryProtocolFactoryDefault(),
}
res.ResourcePool = pools.NewResourcePool(res.factory, n, n, ttl)
return
}
示例4: GuessTransportFactory
func GuessTransportFactory(framed bool, buffer int) (res thrift.TTransportFactory) {
if buffer != 0 {
res = thrift.NewTBufferedTransportFactory(buffer)
} else {
res = thrift.NewTTransportFactory()
}
if framed {
res = thrift.NewTFramedTransportFactory(res)
}
return
}
示例5: Benchmark_Proto_Thrift_Buffered
func Benchmark_Proto_Thrift_Buffered(b *testing.B) {
b.Skip()
server := &TServer{}
err := server.Start(thrift.NewTBufferedTransportFactory(thrift_buffer))
assert.NoError(b, err)
defer server.Server.Stop()
var transport thrift.TTransport
transport, err = thrift.NewTSocket(fmt.Sprintf("127.0.0.1:%d", server.Port))
assert.NoError(b, err)
transportFactory := thrift.NewTBufferedTransportFactory(thrift_buffer)
transport = transportFactory.GetTransport(transport)
err = transport.Open()
assert.NoError(b, err)
defer transport.Close()
protoFactory := thrift.NewTBinaryProtocolFactoryDefault()
client := srv.NewTSrvClientFactory(transport, protoFactory)
b.Log(server.Port, b.N)
b.ResetTimer()
for i := 0; i < b.N; i++ {
b.StartTimer()
req := srv.TestRep{
ID: fmt.Sprintf("%d", i),
Data: []byte("mama myla ramy"),
}
res, err := client.Test(&req)
b.StopTimer()
assert.NoError(b, err)
assert.EqualValues(b, req, *res)
b.SetBytes(int64(len(req.Data) * 2))
}
}
示例6: main
//.........這裏部分代碼省略.........
traceConcat = zipkin.ToContext(newConcatSpan, tracingLogger)
mux = http.NewServeMux()
sum, concat endpoint.Endpoint
)
sum = makeSumEndpoint(svc)
sum = zipkin.AnnotateServer(newSumSpan, collector)(sum)
mux.Handle("/sum", httptransport.NewServer(
root,
sum,
server.DecodeSumRequest,
server.EncodeSumResponse,
httptransport.ServerBefore(traceSum),
httptransport.ServerErrorLogger(transportLogger),
))
concat = makeConcatEndpoint(svc)
concat = zipkin.AnnotateServer(newConcatSpan, collector)(concat)
mux.Handle("/concat", httptransport.NewServer(
root,
concat,
server.DecodeConcatRequest,
server.EncodeConcatResponse,
httptransport.ServerBefore(traceConcat),
httptransport.ServerErrorLogger(transportLogger),
))
transportLogger.Log("addr", *httpAddr)
errc <- http.ListenAndServe(*httpAddr, mux)
}()
// Transport: gRPC
go func() {
transportLogger := log.NewContext(logger).With("transport", "gRPC")
ln, err := net.Listen("tcp", *grpcAddr)
if err != nil {
errc <- err
return
}
s := grpc.NewServer() // uses its own, internal context
pb.RegisterAddServer(s, grpcBinding{svc})
transportLogger.Log("addr", *grpcAddr)
errc <- s.Serve(ln)
}()
// Transport: net/rpc
go func() {
transportLogger := log.NewContext(logger).With("transport", "net/rpc")
s := rpc.NewServer()
if err := s.RegisterName("addsvc", netrpcBinding{svc}); err != nil {
errc <- err
return
}
s.HandleHTTP(rpc.DefaultRPCPath, rpc.DefaultDebugPath)
transportLogger.Log("addr", *netrpcAddr)
errc <- http.ListenAndServe(*netrpcAddr, s)
}()
// Transport: Thrift
go func() {
var protocolFactory thrift.TProtocolFactory
switch *thriftProtocol {
case "binary":
protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
case "compact":
protocolFactory = thrift.NewTCompactProtocolFactory()
case "json":
protocolFactory = thrift.NewTJSONProtocolFactory()
case "simplejson":
protocolFactory = thrift.NewTSimpleJSONProtocolFactory()
default:
errc <- fmt.Errorf("invalid Thrift protocol %q", *thriftProtocol)
return
}
var transportFactory thrift.TTransportFactory
if *thriftBufferSize > 0 {
transportFactory = thrift.NewTBufferedTransportFactory(*thriftBufferSize)
} else {
transportFactory = thrift.NewTTransportFactory()
}
if *thriftFramed {
transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
}
transport, err := thrift.NewTServerSocket(*thriftAddr)
if err != nil {
errc <- err
return
}
transportLogger := log.NewContext(logger).With("transport", "net/rpc")
transportLogger.Log("addr", *thriftAddr)
errc <- thrift.NewTSimpleServer4(
thriftadd.NewAddServiceProcessor(thriftBinding{svc}),
transport,
transportFactory,
protocolFactory,
).Serve()
}()
logger.Log("fatal", <-errc)
}
示例7: main
func main() {
var (
transport = flag.String("transport", "httpjson", "httpjson, grpc, netrpc, thrift")
httpAddr = flag.String("http.addr", "localhost:8001", "Address for HTTP (JSON) server")
grpcAddr = flag.String("grpc.addr", "localhost:8002", "Address for gRPC server")
netrpcAddr = flag.String("netrpc.addr", "localhost:8003", "Address for net/rpc server")
thriftAddr = flag.String("thrift.addr", "localhost:8004", "Address for Thrift server")
thriftProtocol = flag.String("thrift.protocol", "binary", "binary, compact, json, simplejson")
thriftBufferSize = flag.Int("thrift.buffer.size", 0, "0 for unbuffered")
thriftFramed = flag.Bool("thrift.framed", false, "true to enable framing")
)
flag.Parse()
if len(os.Args) < 4 {
fmt.Fprintf(os.Stderr, "\n%s [flags] method arg1 arg2\n\n", filepath.Base(os.Args[0]))
flag.Usage()
os.Exit(1)
}
root := context.Background()
method, s1, s2 := flag.Arg(0), flag.Arg(1), flag.Arg(2)
var logger log.Logger
logger = log.NewLogfmtLogger(os.Stdout)
logger = log.NewContext(logger).With("caller", log.DefaultCaller)
logger = log.NewContext(logger).With("transport", *transport)
var svc server.AddService
switch *transport {
case "grpc":
cc, err := grpc.Dial(*grpcAddr)
if err != nil {
_ = logger.Log("err", err)
os.Exit(1)
}
defer cc.Close()
svc = grpcclient.New(root, cc, logger)
case "httpjson":
rawurl := *httpAddr
if !strings.HasPrefix("http", rawurl) {
rawurl = "http://" + rawurl
}
baseurl, err := url.Parse(rawurl)
if err != nil {
_ = logger.Log("err", err)
os.Exit(1)
}
svc = httpjsonclient.New(root, baseurl, logger, nil)
case "netrpc":
cli, err := rpc.DialHTTP("tcp", *netrpcAddr)
if err != nil {
_ = logger.Log("err", err)
os.Exit(1)
}
defer cli.Close()
svc = netrpcclient.New(cli, logger)
case "thrift":
var protocolFactory thrift.TProtocolFactory
switch *thriftProtocol {
case "compact":
protocolFactory = thrift.NewTCompactProtocolFactory()
case "simplejson":
protocolFactory = thrift.NewTSimpleJSONProtocolFactory()
case "json":
protocolFactory = thrift.NewTJSONProtocolFactory()
case "binary", "":
protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
default:
_ = logger.Log("protocol", *thriftProtocol, "err", "invalid protocol")
os.Exit(1)
}
var transportFactory thrift.TTransportFactory
if *thriftBufferSize > 0 {
transportFactory = thrift.NewTBufferedTransportFactory(*thriftBufferSize)
} else {
transportFactory = thrift.NewTTransportFactory()
}
if *thriftFramed {
transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
}
transportSocket, err := thrift.NewTSocket(*thriftAddr)
if err != nil {
_ = logger.Log("during", "thrift.NewTSocket", "err", err)
os.Exit(1)
}
trans := transportFactory.GetTransport(transportSocket)
defer trans.Close()
if err := trans.Open(); err != nil {
_ = logger.Log("during", "thrift transport.Open", "err", err)
os.Exit(1)
}
cli := thriftadd.NewAddServiceClientFactory(trans, protocolFactory)
svc = thriftclient.New(cli, logger)
default:
_ = logger.Log("err", "invalid transport")
os.Exit(1)
}
//.........這裏部分代碼省略.........
示例8: main
//.........這裏部分代碼省略.........
e = zipkin.AnnotateServer(zipkinSpanFunc, zipkinCollector)(e)
// Mechanical stuff
rand.Seed(time.Now().UnixNano())
root := context.Background()
errc := make(chan error)
go func() {
errc <- interrupt()
}()
// Transport: HTTP (debug/instrumentation)
go func() {
logger.Log("addr", *debugAddr, "transport", "debug")
errc <- http.ListenAndServe(*debugAddr, nil)
}()
// Transport: HTTP (JSON)
go func() {
ctx, cancel := context.WithCancel(root)
defer cancel()
before := []httptransport.BeforeFunc{zipkin.ToContext(zipkinSpanFunc)}
after := []httptransport.AfterFunc{}
handler := makeHTTPBinding(ctx, e, before, after)
logger.Log("addr", *httpAddr, "transport", "HTTP/JSON")
errc <- http.ListenAndServe(*httpAddr, handler)
}()
// Transport: gRPC
go func() {
ln, err := net.Listen("tcp", *grpcAddr)
if err != nil {
errc <- err
return
}
s := grpc.NewServer() // uses its own context?
pb.RegisterAddServer(s, grpcBinding{e})
logger.Log("addr", *grpcAddr, "transport", "gRPC")
errc <- s.Serve(ln)
}()
// Transport: net/rpc
go func() {
ctx, cancel := context.WithCancel(root)
defer cancel()
s := rpc.NewServer()
s.RegisterName("addsvc", NetrpcBinding{ctx, e})
s.HandleHTTP(rpc.DefaultRPCPath, rpc.DefaultDebugPath)
logger.Log("addr", *netrpcAddr, "transport", "net/rpc")
errc <- http.ListenAndServe(*netrpcAddr, s)
}()
// Transport: Thrift
go func() {
ctx, cancel := context.WithCancel(root)
defer cancel()
var protocolFactory thrift.TProtocolFactory
switch *thriftProtocol {
case "binary":
protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
case "compact":
protocolFactory = thrift.NewTCompactProtocolFactory()
case "json":
protocolFactory = thrift.NewTJSONProtocolFactory()
case "simplejson":
protocolFactory = thrift.NewTSimpleJSONProtocolFactory()
default:
errc <- fmt.Errorf("invalid Thrift protocol %q", *thriftProtocol)
return
}
var transportFactory thrift.TTransportFactory
if *thriftBufferSize > 0 {
transportFactory = thrift.NewTBufferedTransportFactory(*thriftBufferSize)
} else {
transportFactory = thrift.NewTTransportFactory()
}
if *thriftFramed {
transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
}
transport, err := thrift.NewTServerSocket(*thriftAddr)
if err != nil {
errc <- err
return
}
logger.Log("addr", *thriftAddr, "transport", "Thrift")
errc <- thrift.NewTSimpleServer4(
thriftadd.NewAddServiceProcessor(thriftBinding{ctx, e}),
transport,
transportFactory,
protocolFactory,
).Serve()
}()
logger.Log("fatal", <-errc)
}
示例9: main
func main() {
// Flag domain. Note that gRPC transitively registers flags via its import
// of glog. So, we define a new flag set, to keep those domains distinct.
fs := flag.NewFlagSet("", flag.ExitOnError)
var (
transport = fs.String("transport", "grpc", "http, grpc, netrpc, thrift")
httpAddr = fs.String("http.addr", "localhost:8001", "HTTP (JSON) address")
grpcAddr = fs.String("grpc.addr", "localhost:8002", "gRPC address")
netrpcAddr = fs.String("netrpc.addr", "localhost:8003", "net/rpc address")
thriftAddr = fs.String("thrift.addr", "localhost:8004", "Thrift address")
thriftProtocol = fs.String("thrift.protocol", "binary", "binary, compact, json, simplejson")
thriftBufferSize = fs.Int("thrift.buffer.size", 0, "0 for unbuffered")
thriftFramed = fs.Bool("thrift.framed", false, "true to enable framing")
a = fs.Int64("a", 1, "a value")
b = fs.Int64("b", 2, "b value")
)
flag.Usage = fs.Usage // only show our flags
fs.Parse(os.Args[1:])
log.SetFlags(0)
log.SetOutput(os.Stdout)
var e endpoint.Endpoint
switch *transport {
case "http":
if !strings.HasPrefix(*httpAddr, "http") {
*httpAddr = "http://" + *httpAddr
}
u, err := url.Parse(*httpAddr)
if err != nil {
log.Fatalf("url.Parse: %v", err)
}
if u.Path == "" {
u.Path = "/add"
}
e = httpclient.NewClient("GET", u.String())
case "grpc":
cc, err := grpc.Dial(*grpcAddr)
if err != nil {
log.Fatalf("grpc.Dial: %v", err)
}
e = grpcclient.NewClient(cc)
case "netrpc":
client, err := rpc.DialHTTP("tcp", *netrpcAddr)
if err != nil {
log.Fatalf("rpc.DialHTTP: %v", err)
}
e = netrpcclient.NewClient(client)
case "thrift":
var protocolFactory thrift.TProtocolFactory
switch *thriftProtocol {
case "compact":
protocolFactory = thrift.NewTCompactProtocolFactory()
case "simplejson":
protocolFactory = thrift.NewTSimpleJSONProtocolFactory()
case "json":
protocolFactory = thrift.NewTJSONProtocolFactory()
case "binary", "":
protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
default:
log.Fatalf("invalid protocol %q", *thriftProtocol)
}
var transportFactory thrift.TTransportFactory
if *thriftBufferSize > 0 {
transportFactory = thrift.NewTBufferedTransportFactory(*thriftBufferSize)
} else {
transportFactory = thrift.NewTTransportFactory()
}
if *thriftFramed {
transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
}
transportSocket, err := thrift.NewTSocket(*thriftAddr)
if err != nil {
log.Fatalf("thrift.NewTSocket: %v", err)
}
transport := transportFactory.GetTransport(transportSocket)
defer transport.Close()
if err := transport.Open(); err != nil {
log.Fatalf("Thrift transport.Open: %v", err)
}
e = thriftclient.NewClient(thriftadd.NewAddServiceClientFactory(transport, protocolFactory))
default:
log.Fatalf("unsupported transport %q", *transport)
}
response, err := e(context.Background(), reqrep.AddRequest{A: *a, B: *b})
if err != nil {
log.Fatalf("when invoking request: %v", err)
}
addResponse, ok := response.(reqrep.AddResponse)
if !ok {
log.Fatalf("when type-asserting response: %v", endpoint.ErrBadCast)
//.........這裏部分代碼省略.........
示例10: main
//.........這裏部分代碼省略.........
mux = http.NewServeMux()
sum, concat endpoint.Endpoint
)
sum = makeSumEndpoint(svc)
sum = kitot.TraceServer(tracer, "sum")(sum)
mux.Handle("/sum", httptransport.NewServer(
root,
sum,
server.DecodeSumRequest,
server.EncodeSumResponse,
httptransport.ServerErrorLogger(transportLogger),
httptransport.ServerBefore(kitot.FromHTTPRequest(tracer, "sum", tracingLogger)),
))
concat = makeConcatEndpoint(svc)
concat = kitot.TraceServer(tracer, "concat")(concat)
mux.Handle("/concat", httptransport.NewServer(
root,
concat,
server.DecodeConcatRequest,
server.EncodeConcatResponse,
httptransport.ServerErrorLogger(transportLogger),
httptransport.ServerBefore(kitot.FromHTTPRequest(tracer, "concat", tracingLogger)),
))
transportLogger.Log("addr", *httpAddr)
errc <- http.ListenAndServe(*httpAddr, mux)
}()
// Transport: gRPC
go func() {
transportLogger := log.NewContext(logger).With("transport", "gRPC")
tracingLogger := log.NewContext(transportLogger).With("component", "tracing")
ln, err := net.Listen("tcp", *grpcAddr)
if err != nil {
errc <- err
return
}
s := grpc.NewServer() // uses its own, internal context
pb.RegisterAddServer(s, newGRPCBinding(root, tracer, svc, tracingLogger))
transportLogger.Log("addr", *grpcAddr)
errc <- s.Serve(ln)
}()
// Transport: net/rpc
go func() {
transportLogger := log.NewContext(logger).With("transport", "net/rpc")
s := rpc.NewServer()
if err := s.RegisterName("addsvc", netrpcBinding{svc}); err != nil {
errc <- err
return
}
s.HandleHTTP(rpc.DefaultRPCPath, rpc.DefaultDebugPath)
transportLogger.Log("addr", *netrpcAddr)
errc <- http.ListenAndServe(*netrpcAddr, s)
}()
// Transport: Thrift
go func() {
var protocolFactory thrift.TProtocolFactory
switch *thriftProtocol {
case "binary":
protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
case "compact":
protocolFactory = thrift.NewTCompactProtocolFactory()
case "json":
protocolFactory = thrift.NewTJSONProtocolFactory()
case "simplejson":
protocolFactory = thrift.NewTSimpleJSONProtocolFactory()
default:
errc <- fmt.Errorf("invalid Thrift protocol %q", *thriftProtocol)
return
}
var transportFactory thrift.TTransportFactory
if *thriftBufferSize > 0 {
transportFactory = thrift.NewTBufferedTransportFactory(*thriftBufferSize)
} else {
transportFactory = thrift.NewTTransportFactory()
}
if *thriftFramed {
transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
}
transport, err := thrift.NewTServerSocket(*thriftAddr)
if err != nil {
errc <- err
return
}
transportLogger := log.NewContext(logger).With("transport", "thrift")
transportLogger.Log("addr", *thriftAddr)
errc <- thrift.NewTSimpleServer4(
thriftadd.NewAddServiceProcessor(thriftBinding{svc}),
transport,
transportFactory,
protocolFactory,
).Serve()
}()
logger.Log("fatal", <-errc)
}
示例11: main
//.........這裏部分代碼省略.........
// Mechanical domain.
errc := make(chan error)
ctx := context.Background()
// Interrupt handler.
go func() {
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
errc <- fmt.Errorf("%s", <-c)
}()
// Debug listener.
go func() {
logger := log.NewContext(logger).With("transport", "debug")
m := http.NewServeMux()
m.Handle("/debug/pprof/", http.HandlerFunc(pprof.Index))
m.Handle("/debug/pprof/cmdline", http.HandlerFunc(pprof.Cmdline))
m.Handle("/debug/pprof/profile", http.HandlerFunc(pprof.Profile))
m.Handle("/debug/pprof/symbol", http.HandlerFunc(pprof.Symbol))
m.Handle("/debug/pprof/trace", http.HandlerFunc(pprof.Trace))
m.Handle("/metrics", stdprometheus.Handler())
logger.Log("addr", *debugAddr)
errc <- http.ListenAndServe(*debugAddr, m)
}()
// HTTP transport.
go func() {
logger := log.NewContext(logger).With("transport", "HTTP")
h := addsvc.MakeHTTPHandler(ctx, endpoints, tracer, logger)
logger.Log("addr", *httpAddr)
errc <- http.ListenAndServe(*httpAddr, h)
}()
// gRPC transport.
go func() {
logger := log.NewContext(logger).With("transport", "gRPC")
ln, err := net.Listen("tcp", *grpcAddr)
if err != nil {
errc <- err
return
}
srv := addsvc.MakeGRPCServer(ctx, endpoints, tracer, logger)
s := grpc.NewServer()
pb.RegisterAddServer(s, srv)
logger.Log("addr", *grpcAddr)
errc <- s.Serve(ln)
}()
// Thrift transport.
go func() {
logger := log.NewContext(logger).With("transport", "Thrift")
var protocolFactory thrift.TProtocolFactory
switch *thriftProtocol {
case "binary":
protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
case "compact":
protocolFactory = thrift.NewTCompactProtocolFactory()
case "json":
protocolFactory = thrift.NewTJSONProtocolFactory()
case "simplejson":
protocolFactory = thrift.NewTSimpleJSONProtocolFactory()
default:
errc <- fmt.Errorf("invalid Thrift protocol %q", *thriftProtocol)
return
}
var transportFactory thrift.TTransportFactory
if *thriftBufferSize > 0 {
transportFactory = thrift.NewTBufferedTransportFactory(*thriftBufferSize)
} else {
transportFactory = thrift.NewTTransportFactory()
}
if *thriftFramed {
transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
}
transport, err := thrift.NewTServerSocket(*thriftAddr)
if err != nil {
errc <- err
return
}
logger.Log("addr", *thriftAddr)
errc <- thrift.NewTSimpleServer4(
thriftadd.NewAddServiceProcessor(addsvc.MakeThriftHandler(ctx, endpoints)),
transport,
transportFactory,
protocolFactory,
).Serve()
}()
// Run!
logger.Log("exit", <-errc)
}