// create one client instance func (zt *ZooThrift) createClientFactory() (interface{}, error) { transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()) protocolFactory := thrift.NewTBinaryProtocolFactoryDefault() address := zt.provider.Selector() if address != "" { transport, err := thrift.NewTSocket(address) if err != nil { return nil, err } useTransport := transportFactory.GetTransport(transport) client := reflect.ValueOf(zt.Service) mutable := client.Elem() mutable.FieldByName("Transport").Set(reflect.Value(reflect.ValueOf(useTransport))) mutable.FieldByName("ProtocolFactory").Set(reflect.Value(reflect.ValueOf(protocolFactory))) mutable.FieldByName("InputProtocol").Set(reflect.Value(reflect.ValueOf(protocolFactory.GetProtocol(useTransport)))) mutable.FieldByName("OutputProtocol").Set(reflect.Value(reflect.ValueOf(protocolFactory.GetProtocol(useTransport)))) mutable.FieldByName("SeqId").SetInt(0) if err := transport.Open(); err != nil { return nil, err } return zt.Service, nil } else { return nil, ErrSerAddress } }
// Serve starts service for the given Computation. // // Must be called from main() function of worker. func Serve(comp Computation) error { bindAddr := os.Getenv(bolt.KConcordEnvKeyClientListenAddr) proxyAddr := os.Getenv(bolt.KConcordEnvKeyClientProxyAddr) // Init transport transport, err := thrift.NewTServerSocket(bindAddr) if err != nil { panic("failed to create server") } factory := thrift.NewTTransportFactory() transportF := thrift.NewTFramedTransportFactory(factory) protocolF := thrift.NewTBinaryProtocolFactoryDefault() proxy, err := newProxy(proxyAddr, comp.Metadata()) if err != nil { panic("failed to initialize proxy") } service := newComputationService(comp, proxy) processor := bolt.NewComputationServiceProcessor(service) srv := thrift.NewTSimpleServer4(processor, transport, transportF, protocolF) return srv.Serve() }
func main() { var err error transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()) protocolFactory := thrift.NewTBinaryProtocolFactoryDefault() var transport thrift.TTransport transport, err = thrift.NewTSocket(listen) if err != nil { fmt.Println("error, thrift init!") return } transport = transportFactory.GetTransport(transport) defer transport.Close() if err := transport.Open(); err != nil { fmt.Printf("error %v\n", err) return } client := puller.NewPullerClientFactory(transport, protocolFactory) var request puller.Request request.UserId = 12398 request.Payload = "dlrow olleh" var response *puller.Response response, err = client.Pull(&request) if err != nil { fmt.Printf("error, response[%v]\n", err) return } fmt.Printf("response:[%v]\n", response) }
// go test github.com/citysir/zpush/push -test.v func Test_Push(t *testing.T) { startTime := currentTimeMillis() transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()) protocolFactory := thrift.NewTBinaryProtocolFactoryDefault() transport, err := thrift.NewTSocket("127.0.0.1:19090") if err != nil { t.Log(os.Stderr, "error resolving address:", err) os.Exit(1) } useTransport := transportFactory.GetTransport(transport) client := push.NewPushServiceClientFactory(useTransport, protocolFactory) if err := transport.Open(); err != nil { t.Log(os.Stderr, "Error opening socket to 127.0.0.1:19090", " ", err) os.Exit(1) } defer transport.Close() for i := 0; i < 1000; i++ { paramMap := make(map[string]string) paramMap["name"] = "qinerg" paramMap["passwd"] = "123456" result, err := client.FunCall(currentTimeMillis(), "login", paramMap) t.Log(i, "Call->", result, err) } endTime := currentTimeMillis() t.Log("Program exit. time->", endTime, startTime, (endTime - startTime)) }
func main() { transportFactory := thrift.NewTFramedTransportFactory( thrift.NewTTransportFactory()) protocolFactory := thrift.NewTBinaryProtocolFactoryDefault() addr := "localhost:3636" socket, err := thrift.NewTSocket(addr) if err != nil { panic(err) } transport := transportFactory.GetTransport(socket) defer transport.Close() if err := transport.Open(); err != nil { panic(err) } client := hello.NewHelloClientFactory(transport, protocolFactory) request := hello.NewHelloRequest() request.Message = "world!" response, err := client.Hello(request) if err != nil { panic(err) } fmt.Println(response.Message) }
func main() { startTime := currentTimeMillis() transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()) protocolFactory := thrift.NewTBinaryProtocolFactoryDefault() transport, err := thrift.NewTSocket(net.JoinHostPort("127.0.0.1", "19090")) if err != nil { fmt.Fprintln(os.Stderr, "error resolving address:", err) os.Exit(1) } useTransport := transportFactory.GetTransport(transport) client := rpc.NewRpcServiceClientFactory(useTransport, protocolFactory) if err := transport.Open(); err != nil { fmt.Fprintln(os.Stderr, "Error opening socket to 127.0.0.1:19090", " ", err) os.Exit(1) } defer transport.Close() for i := 0; i < 1000; i++ { paramMap := make(map[string]string) paramMap["name"] = "qinerg" paramMap["passwd"] = "123456" r1, e1 := client.FunCall(currentTimeMillis(), "login", paramMap) fmt.Println(i, "Call->", r1, e1) } endTime := currentTimeMillis() fmt.Println("Program exit. time->", endTime, startTime, (endTime - startTime)) }
func (self *FlumeClient) Connect() error { var tsocket *thrift.TSocket var err error //创建一个物理连接 tsocket, err = thrift.NewTSocketTimeout(net.JoinHostPort(self.host, strconv.Itoa(self.port)), 10*time.Second) if nil != err { log.Printf("FLUME_CLIENT|CREATE TSOCKET|FAIL|%s|%s\n", self.HostPort(), err) return err } self.tsocket = tsocket transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()) //TLV 方式传输 protocolFactory := thrift.NewTCompactProtocolFactory() //使用非阻塞io来传输 self.transport = transportFactory.GetTransport(tsocket) self.thriftclient = flume.NewThriftSourceProtocolClientFactory(self.transport, protocolFactory) if err := self.transport.Open(); nil != err { log.Printf("FLUME_CLIENT|CREATE THRIFT CLIENT|FAIL|%s|%s", self.HostPort(), err) return err } self.status = STATUS_READY go self.checkAlive() return nil }
func (self *FlumeClient) Connect() { //创建一个物理连接 tsocket, err := thrift.NewTSocket(net.JoinHostPort(self.host, strconv.Itoa(self.port))) if nil != err { log.Panic(err) os.Exit(-1) } transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()) //TLV 方式传输 protocolFactory := thrift.NewTCompactProtocolFactory() //使用非阻塞io来传输 self.transport = transportFactory.GetTransport(tsocket) self.thriftclient = flume.NewThriftSourceProtocolClientFactory(self.transport, protocolFactory) if err := self.transport.Open(); nil != err { log.Panic(err) os.Exit(-1) } self.status = STATUS_READY go self.checkAlive() }
func main() { startTime := currentTimeMillis() transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()) protocolFactory := thrift.NewTBinaryProtocolFactoryDefault() transport, err := thrift.NewTSocket(NETWORK_ADDR) if err != nil { logrus.Fatal(os.Stderr, "error resolving address:", err) } useTransport := transportFactory.GetTransport(transport) client := rpc.NewSessionManagerClientFactory(useTransport, protocolFactory) if err := transport.Open(); err != nil { logrus.Fatal(os.Stderr, "Error opening socket to "+NETWORK_ADDR, err) } defer transport.Close() // 开始调用服务的接口 ctx := rpc.NewSessionContext() sid, _ := client.CreateSession(ctx) logrus.Infof("创新新的会话id => %s", sid) ctx, _ = client.GetSession(sid) logrus.Infof("获取会话上下文 => %+v", ctx) endTime := currentTimeMillis() logrus.Infof("本次调用用时: %d 毫秒", endTime-startTime) }
func clientCall(min int32) { startTime := currentTimeMillis() transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()) protocolFactory := thrift.NewTBinaryProtocolFactoryDefault() transport, err := thrift.NewTSocket(NetworkAddr) for err != nil { transport, err = thrift.NewTSocket(NetworkAddr) if err != nil { log.Error("error resolving address:", err) } time.Sleep(1 * time.Second) } useTransport := transportFactory.GetTransport(transport) client := demo.NewRpcServiceClientFactory(useTransport, protocolFactory) if err := transport.Open(); err != nil { log.Error("Error opening socket to 127.0.0.1:19090", " ", err) return } defer transport.Close() for i := min; i < min+3; i++ { r1, e1 := client.Add(i, i+1) log.Trace("%d %s %v %v", i, "Call->", r1, e1) } endTime := currentTimeMillis() log.Trace("Program exit. time->", endTime, startTime, (endTime - startTime)) }
// create a new PelicanClient instance for a given host func NewPelicanClient(host string) *PelicanClient { // init client and catch any errors socket, err := thrift.NewTSocket(host) if err != nil { panic(err) } // create a transport factory transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()) // create a binary protocal factory protocolFactory := thrift.NewTBinaryProtocolFactoryDefault() // create a binary transport for the socket transport := transportFactory.GetTransport(socket) // create a new Pelican User service client client := user.NewUserSvcClientFactory(transport, protocolFactory) // fill our wrapper struct return &PelicanClient{ Host: host, Transport: transport, Client: client, } }
func main() { flag.Usage = Usage protocol := flag.String("P", "binary", "Specify the protocol (binary, compact, json, simplejson)") transport := flag.String("transport", "binary", "Specify transport (framed, buffered, file, memory, zlib)") buffered := flag.String("buffered", "off", "Use buffered transport") framed := flag.String("framed", "off", "Use framed transport") addr := flag.String("addr", "localhost:9090", "Address to listen to") secure := flag.Bool("secure", false, "Use tls secure transport") conf_path := flag.String("conf", "nil", "配置文件路径") flag.Parse() if *conf_path == "nil" { Usage() os.Exit(1) } 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: fmt.Fprint(os.Stderr, "Invalid protocol specified", protocol, "\n") Usage() os.Exit(1) } var transportFactory thrift.TTransportFactory if *buffered == "on" { transportFactory = thrift.NewTBufferedTransportFactory(8192) } else { transportFactory = thrift.NewTTransportFactory() } if *framed == "on" { transportFactory = thrift.NewTFramedTransportFactory(transportFactory) } //获取配置文件的路径 complete_path(conf_path) //初始化控制层 handler.Init(*conf_path) if err := runServer(transportFactory, *transport, protocolFactory, *addr, *secure); err != nil { fmt.Println("error running server:", err) } }
func InitControllerRpcClient() error { // //startTime := currentTimeMillis() // transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()) // protocolFactory := thrift.NewTBinaryProtocolFactoryDefault() // // transport, err := thrift.NewTSocket(net.JoinHostPort(Conf.ControllerServerIp, Conf.ControllerServerPort)) // if err != nil { // fmt.Fprintln(os.Stderr, "error resolving address:", err) // return nil // } // // useTransport := transportFactory.GetTransport(transport) // controllerClient = controller.NewControllerRpcServiceClientFactory(useTransport, protocolFactory) // if err := useTransport.Open(); err != nil { // fmt.Fprintln(os.Stderr, "Error opening socket to "+Conf.ControllerServerIp+":"+Conf.ControllerServerPort, " ", err) // return err // } // //defer transport.Close() // return nil thriftPool = &Pool{ Dial: func() (interface{}, error) { transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()) protocolFactory := thrift.NewTBinaryProtocolFactoryDefault() transport, err := thrift.NewTSocket(net.JoinHostPort(Conf.ControllerServerIp, Conf.ControllerServerPort)) if err != nil { log.Error("error resolving address: %s, port: %s error(%v)", Conf.ControllerServerIp, Conf.ControllerServerPort, err) return nil, err } useTransport := transportFactory.GetTransport(transport) client := controller.NewControllerRpcServiceClientFactory(useTransport, protocolFactory) if err = client.Transport.Open(); err != nil { log.Error("client.Transport.Open() error(%v)", err) return nil, err } return client, nil }, Close: func(v interface{}) error { v.(*controller.ControllerRpcServiceClient).Transport.Close() return nil }, TestOnBorrow: func(v interface{}) error { if v.(*controller.ControllerRpcServiceClient).Transport.IsOpen() { return nil } else { return ErrConnectionClosed } }, MaxActive: Conf.ThriftMaxActive, MaxIdle: Conf.ThriftMaxIdle, IdleTimeout: time.Duration(Conf.ThriftIdleTimeout), } return nil }
func main() { socket, err := thrift.NewTSocket("localhost:4000") if err != nil { panic(err) } transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()) protocolFactory := thrift.NewTBinaryProtocolFactoryDefault() transport := transportFactory.GetTransport(socket) client := microservice.NewPersonServiceClientFactory(transport, protocolFactory) defer client.Transport.Close() if err := client.Transport.Open(); err != nil { panic(err) } p1 := NewPersonInit(1, "Dimas", "Ragil T", "*****@*****.**", 20, true) p1, err = client.Create(p1) if err != nil { panic(err) } p2, err := client.Read(p1.ID) if err != nil { panic(err) } fmt.Println(p2.ID, p2.Firstname, *p2.Lastname, *p2.Email, p2.Age, p2.Active) p3 := NewPersonInit(2, "Ratna", "Siwi Y", "*****@*****.**", 20, true) p3, err = client.Create(p3) if err != nil { panic(err) } p4, err := client.Read(p3.ID) if err != nil { panic(err) } fmt.Println(p4.ID, p4.Firstname, *p4.Lastname, *p4.Email, p4.Age, p4.Active) p5 := NewPersonInit(1, "Dimas", "Ragil T", "*****@*****.**", 20, false) p5, err = client.Update(p5) if err != nil { panic(err) } p6, err := client.GetAll() for _, person := range p6 { fmt.Println(person.ID, person.Firstname, *person.Lastname, *person.Email, person.Age, person.Active) } p7 := client.Destroy(p5.ID) if p7 != nil { panic(err) } p8, err := client.GetAll() for _, person := range p8 { fmt.Println(person.ID, person.Firstname, *person.Lastname, *person.Email, person.Age, person.Active) } }
// run a test flume agent func runDummyFlumeAgent(t *testing.T) { transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()) protocolFactory := thrift.NewTCompactProtocolFactory() transport, _ := thrift.NewTServerSocket("localhost:51515") handler := thriftSourceProtocolHandler{t} processor := flume.NewThriftSourceProtocolProcessor(handler) server := thrift.NewTSimpleServer4(processor, transport, transportFactory, protocolFactory) server.Serve() }
func NewThriftExporter(addr string, reg registry.Registry) *ThriftExporter { return &ThriftExporter{ Provider: registry.ProviderInfo{Addr: addr, Status: 0, Weight: 5}, Reg: reg, Config: &ThriftConfig{ TransFactory: thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()), ProtocolFactory: thrift.NewTBinaryProtocolFactoryDefault(), Secure: false, }, } }
func main() { var networkAddr = flag.String("addr", "localhost:9090", "会话服务器地址") flag.Parse() transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()) protocolFactory := thrift.NewTBinaryProtocolFactoryDefault() //protocolFactory := thrift.NewTCompactProtocolFactory() if err := service.RunNonSecureServer(transportFactory, protocolFactory, *networkAddr); err != nil { logrus.Fatal(err) } }
func main() { protocolFactory := thrift.NewTBinaryProtocolFactoryDefault() transport, err := thrift.NewTServerSocket("localhost:8090") if err != nil { fmt.Printf("There was an error creating your socket! Here it is %v", err) } transportFactory := thrift.NewTTransportFactory() processor := service.NewMakeTagsProcessor(handler.NewTagsHandler(os.Getenv("ACCESS_TOKEN"))) server := thrift.NewTSimpleServer4(processor, transport, transportFactory, protocolFactory) fmt.Printf("server listening on %s\n", "localhost:8090") server.Serve() }
func main() { handler := NewCoffeeOrderHandler() processor := co.NewCoffeeOrderProcessor(handler) protocolFactory := thrift.NewTBinaryProtocolFactoryDefault() transportFactory := thrift.NewTTransportFactory() serverTransport, err := thrift.NewTServerSocket("0.0.0.0:9090") if err != nil { log.Println(err) } server := thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory) server.Serve() }
func NewHCatClient(addr string) (*HCatClient, error) { transportFactory := thrift.NewTTransportFactory() protocolFactory := thrift.NewTBinaryProtocolFactoryDefault() socket, err := thrift.NewTSocket(addr) if err != nil { return nil, err } transport := transportFactory.GetTransport(socket) mstore := hive.NewThriftHiveMetastoreClientFactory(transport, protocolFactory) // return &HCatClient{ mstore, socket }, nil return &HCatClient{*mstore, socket}, nil }
func (this *Engine) launchRpcServe() (done chan interface{}) { var protocolFactory thrift.TProtocolFactory switch this.conf.rpc.protocol { case "binary": protocolFactory = thrift.NewTBinaryProtocolFactoryDefault() case "json": protocolFactory = thrift.NewTJSONProtocolFactory() case "simplejson": protocolFactory = thrift.NewTSimpleJSONProtocolFactory() case "compact": protocolFactory = thrift.NewTCompactProtocolFactory() default: panic(fmt.Sprintf("Invalid protocol: %s", this.conf.rpc.protocol)) } transportFactory := thrift.NewTTransportFactory() if this.conf.rpc.framed { transportFactory = thrift.NewTFramedTransportFactory(transportFactory) } serverTransport, err := thrift.NewTServerSocketTimeout(this.conf.rpc.listenAddr, this.conf.rpc.clientTimeout) if err != nil { panic(err) } this.rpcServer = thrift.NewTSimpleServer4(this.rpcProcessor, serverTransport, transportFactory, protocolFactory) log.Info("RPC server ready at %s", this.conf.rpc.listenAddr) done = make(chan interface{}) go func() { for { err = this.rpcServer.Serve() if err != nil { log.Error(err) break } } done <- 1 }() return done }
func main() { transport, err := thrift.NewTServerSocket("localhost:3636") if err != nil { panic(err) } proc := hello.NewHelloProcessor(&HelloHandler{}) server := thrift.NewTSimpleServer4( proc, transport, thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()), thrift.NewTBinaryProtocolFactoryDefault()) println(server.Serve()) }
func startRpcServe(port string) { socket, err := thrift.NewTServerSocketTimeout(fmt.Sprintf(":%s", port), TIMEOUT) if err != nil { log.Fatalln("Unable to create server socket", err) } protocol := thrift.NewTBinaryProtocolFactoryDefault() transport := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()) processor := thrift.NewTMultiplexedProcessor() registerProcessors(processor) server := thrift.NewTSimpleServer4(processor, socket, transport, protocol) server.Serve() }
func main() { flag.Usage = Usage server := flag.Bool("server", false, "Run server") protocol := flag.String("P", "binary", "Specify the protocol (binary, compact, json, simplejson)") framed := flag.Bool("framed", false, "Use framed transport") buffered := flag.Bool("buffered", false, "Use buffered transport") addr := flag.String("addr", nats.DefaultURL, "NATS address to connect to") secure := flag.Bool("secure", false, "Use tls secure transport") flag.Parse() 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: fmt.Fprint(os.Stderr, "Invalid protocol specified", protocol, "\n") Usage() os.Exit(1) } var transportFactory thrift.TTransportFactory if *buffered { transportFactory = thrift.NewTBufferedTransportFactory(8192) } else { transportFactory = thrift.NewTTransportFactory() } if *framed { transportFactory = thrift.NewTFramedTransportFactory(transportFactory) } if *server { if err := runServer(transportFactory, protocolFactory, *addr, *secure); err != nil { fmt.Println("error running server:", err) } } else { if err := runClient(transportFactory, protocolFactory, *addr, *secure); err != nil { fmt.Println("error running client:", err) } } }
func main() { var listen string = ":10001" transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()) protocolFactory := thrift.NewTBinaryProtocolFactoryDefault() serverTransport, err := thrift.NewTServerSocket(listen) if err != nil { fmt.Println("error, thrift init!") return } handler := &Puller{0} processor := puller.NewPullerProcessor(handler) server := thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory) fmt.Printf("server started\n") server.Serve() }
func New(addr string, processor *thrift.TProcessor) (*Server, error) { // Instantiate the thrift server components protocolFactory := thrift.NewTBinaryProtocolFactoryDefault() transportFactory := thrift.NewTTransportFactory() transport, err := thrift.NewTServerSocket(addr) if err != nil { return nil, err } wait := make(chan error) s := Server{Addr: addr, wait: wait, Wait: wait} s.server = thrift.NewTSimpleServer4(*processor, transport, transportFactory, protocolFactory) return &s, nil }
func runServer(listenIp *string, listenPort *int, backendIp *string, backendPort *int, debug *bool) error { transport, err := thrift.NewTServerSocket(fmt.Sprintf("%s:%d", *listenIp, *listenPort)) if err != nil { return err } transportFactory := thrift.NewTTransportFactory() protocolFactory := thrift.NewTBinaryProtocolFactoryDefault() handler := NewDataStoreHandler(backendIp, backendPort, debug) processor := messages.NewDataStoreProcessor(handler) server := thrift.NewTSimpleServer4(processor, transport, transportFactory, protocolFactory) logger.Printf("Thrift Service configured") return server.Serve() }
func GetAll(c *gin.Context) { protocolFactory := thrift.NewTBinaryProtocolFactoryDefault() transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()) result, err := service.GetAll(transportFactory, protocolFactory) if err != nil { m := fmt.Sprintf("%v", err) c.JSON(http.StatusExpectationFailed, util.FailResponse(m)) } else { parse := make([]interface{}, len(result)) for i := range result { parse[i] = model.PersonResponse(result[i]) } c.JSON(http.StatusCreated, util.ListResponse("success", "", parse)) } }
func runThriftServer(host string, port int, protocol string, framed bool, buffered bool, workerId uint64, datacenterId uint64) { 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: fmt.Fprint(os.Stderr, "Invalid protocol specified", protocol, "\n") Usage() os.Exit(1) } var transportFactory thrift.TTransportFactory if buffered { transportFactory = thrift.NewTBufferedTransportFactory(8192) } else { transportFactory = thrift.NewTTransportFactory() } if framed { transportFactory = thrift.NewTFramedTransportFactory(transportFactory) } var err error var transport thrift.TServerTransport transport, err = thrift.NewTServerSocket(fmt.Sprintf("%s:%d", host, port)) if err != nil { log.Fatal(err) os.Exit(1) } worker, err := idworker.NewIdWorker(workerId, datacenterId) processor := snowflake.NewSnowflakeProcessor(worker) if err == nil { server := thrift.NewTSimpleServer4(processor, transport, transportFactory, protocolFactory) server.Serve() } else { log.Fatal(err) } }
func main() { transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()) protocolFactory := thrift.NewTBinaryProtocolFactoryDefault() serverTransport, err := thrift.NewTServerSocket(NetworkAddr) if err != nil { fmt.Println("Error!", err) os.Exit(1) } handler := &RpcServiceImpl{} processor := push.NewPushServiceProcessor(handler) server := thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory) fmt.Println("thrift server in", NetworkAddr) server.Serve() }