コード例 #1
0
ファイル: test_thrift.go プロジェクト: playnb/grasslands
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))
}
コード例 #2
0
ファイル: client.go プロジェクト: faiq/intro-to-rpc
func main() {
	socket, err := thrift.NewTSocket("localhost:8090")
	if err != nil {
		fmt.Printf("There was an error creating your socket! Here it is %v", err)
		os.Exit(1)
	}
	transport := thrift.NewTBufferedTransport(socket, 1024)
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
	client := service.NewMakeTagsClientFactory(transport, protocolFactory)
	pwd, _ := os.Getwd()
	fileName := pwd + "/img.png"
	fileName, _ = filepath.Abs(fileName)
	imgBytes, err := ioutil.ReadFile(fileName)
	if err != nil {
		fmt.Printf("There was an err reading the file! Here it is %v", err)
		os.Exit(1)
	}

	socket.Open()
	tags, err := client.Generate(service.Image(imgBytes))
	if err != nil {
		fmt.Printf("There was an err getting the tags! Here it is %v ", err)
		os.Exit(1)
	}
	fmt.Printf("These are the tags for your image %v", tags)
	socket.Close()
}
コード例 #3
0
ファイル: main.go プロジェクト: ypyf/golang-study
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)

}
コード例 #4
0
// opens a hive connection
func (conn *HiveConnection) Open() error {

	log.Println("creating new hive connection ")
	var transport thrift.TTransport
	var err error
	transport, err = thrift.NewTSocket(conn.Server)
	if err != nil {
		return err
	}
	if transport == nil {
		return errors.New("No TSocket connection?")
	}

	transport.Open()

	// NewTBinaryProtocolTransport(t TTransport) *TBinaryProtocol {
	protocolfac := thrift.NewTBinaryProtocolFactoryDefault()

	//NewThriftHiveClientProtocol(t thrift.TTransport, iprot thrift.TProtocol, oprot thrift.TProtocol)
	conn.Client = thrifthive.NewThriftHiveClientFactory(transport, protocolfac)

	log.Printf("is open? %v", transport.IsOpen())
	name, err := conn.Client.GetName()
	log.Printf("in conn.Open, how is client? %v %v", name, err)

	if conn.Client == nil {
		log.Println("ERROR, no client")
		return errors.New("no client")
	}

	return nil
}
コード例 #5
0
ファイル: connection.go プロジェクト: charithe/hivething
func Connect(host string, options Options) (*Connection, error) {
	transport, err := thrift.NewTSocket(host)
	if err != nil {
		return nil, err
	}

	if err := transport.Open(); err != nil {
		return nil, err
	}

	if transport == nil {
		return nil, errors.New("nil thrift transport")
	}

	/*
		NB: hive 0.13's default is a TSaslProtocol, but
		there isn't a golang implementation in apache thrift as
		of this writing.
	*/
	protocol := thrift.NewTBinaryProtocolFactoryDefault()
	client := tcliservice.NewTCLIServiceClientFactory(transport, protocol)

	session, err := client.OpenSession(*tcliservice.NewTOpenSessionReq())
	if err != nil {
		return nil, err
	}

	return &Connection{client, session.SessionHandle, options}, nil
}
コード例 #6
0
ファイル: zoothrift.go プロジェクト: nosix-me/zoothrift
// 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
	}
}
コード例 #7
0
ファイル: 20120302_thrift_cli.go プロジェクト: bonly/exercise
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))
}
コード例 #8
0
ファイル: pelican.go プロジェクト: mdennebaum/narwhal
// 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,
	}

}
コード例 #9
0
ファイル: main.go プロジェクト: visilicon/thrift-go
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)
}
コード例 #10
0
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)
}
コード例 #11
0
ファイル: main_test.go プロジェクト: citysir/zpush
// 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))
}
コード例 #12
0
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))
}
コード例 #13
0
ファイル: xmail.go プロジェクト: dogeerf/tool
func SendSms(msgSend string, phones_slice []int64) {
	// random choice host
	hosts := []string{"10.231.144.136", "10.231.144.137"}
	rk := GenRandn(len(hosts))
	host := hosts[rk]
	port := "9090"

	transport, err := thrift.NewTSocket(net.JoinHostPort(host, port))
	if err != nil {
		fmt.Fprintln(os.Stderr, "error resolving address:", err)
		os.Exit(1)
	}
	transportFactory := thrift.NewTBufferedTransportFactory(10240)
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()

	useTransport := transportFactory.GetTransport(transport)
	client := sms.NewMessageServiceClientFactory(useTransport, protocolFactory)
	if err := transport.Open(); err != nil {
		fmt.Fprintln(os.Stderr, "Error opening socket to ", host, ":", port, " ", err)
		os.Exit(1)
	}
	defer transport.Close()

	msg := sms.NewMessage()
	msg.Phones = phones_slice
	msg.BusinessId = 200100000
	msg.Message = msgSend
	client.SendMessage(msg)
}
コード例 #14
0
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()
}
コード例 #15
0
ファイル: coffee_client.go プロジェクト: RobWC/thrift-coffee
func main() {
	transport, err := thrift.NewTSocket(net.JoinHostPort("127.0.0.1", "9090"))
	if err != nil {
		log.Println(err)
	}
	defer transport.Close()

	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
	client := CoffeeService.NewCoffeeOrderClientFactory(transport, protocolFactory)
	if err := transport.Open(); err != nil {
		log.Println(err)
		os.Exit(1)
	}

	coffee := CoffeeService.NewCoffee()
	coffee.Name = "foo"
	coffee.Creamers = []*CoffeeService.Creamer{&CoffeeService.Creamer{Name: "Fruit"}}
	coffee.Sweetners = []*CoffeeService.Sweetner{&CoffeeService.Sweetner{Name: "Yum", Amount: 3}}
	coffee.Temperature = 140
	coffee.Iced = false
	coffee.Size = &CoffeeService.Size{Name: "Venti", Ounces: 20}

	log.Println(coffee)

	log.Println(client.Ping())
	log.Println(client.OrderCoffee(coffee))
}
コード例 #16
0
ファイル: rpc-controller-client.go プロジェクト: humortian/im
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
}
コード例 #17
0
ファイル: client.go プロジェクト: dynastymasra/GolangThrift
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)
	}
}
コード例 #18
0
ファイル: glumelogger.go プロジェクト: ceocoder/glumelogger
// NewGlumeLogger create a new GlumeLogger client, it requires a host, port and
// map of headers
func NewGlumeLogger(host string, port int, headers *map[string]string) *GlumeLogger {
	var trans thrift.TTransport
	trans, err := thrift.NewTSocket(net.JoinHostPort(host, strconv.Itoa(port)))
	if err != nil {
		fmt.Fprintln(os.Stderr, "error resolving address:", err)
		os.Exit(1)
	}
	trans = thrift.NewTFramedTransport(trans)
	client := flume.NewThriftSourceProtocolClientFactory(trans, thrift.NewTCompactProtocolFactory())
	return &GlumeLogger{client, headers, &sync.Mutex{}, log.New(os.Stdout, "[GlumeLogger] ", log.Ldate|log.Ltime)}
}
コード例 #19
0
ファイル: esthrift.go プロジェクト: voidabhi/golang-scripts
func Connect(host string, thriftPort string) (*elasticsearch.RestClient, error) {
	binaryProtocol := thrift.NewTBinaryProtocolFactoryDefault()
	socket, err := thrift.NewTSocket(net.JoinHostPort(host, thriftPort))
	if err != nil {
		return nil, err
	}
	bufferedTransport := thrift.NewTBufferedTransport(socket, BUFFER_SIZE)
	client := elasticsearch.NewRestClientFactory(bufferedTransport, binaryProtocol)
	if err := bufferedTransport.Open(); err != nil {
		return nil, err
	}
	return client, nil
}
コード例 #20
0
ファイル: client.go プロジェクト: Rheeseyb/thrift
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))
}
コード例 #21
0
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
}
コード例 #22
0
// Try to establish the thrift connection to specific host and port.
func (self *ThriftHandler) connect() error {
	address := fmt.Sprintf("%s:%d", self.host, self.port)
	socket, err := thrift.NewTSocket(address)
	if err != nil {
		return err
	}
	transport := thrift.NewTFramedTransport(socket)
	factory := thrift.NewTBinaryProtocolFactoryDefault()
	client := gen.NewThriftLoggingServiceClientFactory(transport, factory)
	if err := transport.Open(); err != nil {
		return err
	}
	self.transport = transport
	self.client = client
	return nil
}
コード例 #23
0
ファイル: servant.go プロジェクト: justinblah/fae
func Servant(serverAddr string) *rpc.FunServantClient {
	transportFactory := thrift.NewTTransportFactory()
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()

	transport, err := thrift.NewTSocket(serverAddr)
	if err != nil {
		panic(err)
	}

	useTransport := transportFactory.GetTransport(transport)
	client := rpc.NewFunServantClientFactory(useTransport, protocolFactory)
	if err := transport.Open(); err != nil {
		panic(err)
	}

	return client
}
コード例 #24
0
ファイル: scribe.go プロジェクト: wanyisunflower/scribe-go
func NewScribeLoger(host, port string) (*ScribeLoger, error) {
	Ttransport, err := thrift.NewTSocket(net.JoinHostPort(host, port))
	if err != nil {
		return nil, err
	}
	transport := thrift.NewTFramedTransport(Ttransport)

	protocol := thrift.NewTBinaryProtocol(transport, false, false)

	client := scribe.NewScribeClientProtocol(transport, protocol, protocol)
	if err := transport.Open(); err != nil {
		return nil, err
	}
	return &ScribeLoger{
		transport: transport,
		client:    client,
	}, nil
}
コード例 #25
0
//创建一个thrift的client
func CreateConnection() (interface{}, error) {
	var client *hello.HelloClient
	var transport thrift.TTransport
	transportFactory := thrift.NewTTransportFactory()
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
	raw_transport, e1 := thrift.NewTSocket(net.JoinHostPort(CTR_HOST, CTR_HOST_PORT))
	if e1 != nil {
		return client, e1
	}
	transport = transportFactory.GetTransport(raw_transport)
	e2 := transport.Open()
	if e2 != nil {
		return client, e2
	}

	client = hello.NewHelloClientFactory(transport, protocolFactory)
	return client, nil
}
コード例 #26
0
ファイル: thrift.go プロジェクト: allenma/gosoa
func (t *ThriftClient) createService(addr string) (service *ServiceWrapper, err error) {
	transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())

	socket, err := thrift.NewTSocket(addr)
	transport := transportFactory.GetTransport(socket)
	err = transport.Open()
	if err != nil {
		return nil, err
	} else {
		rfun := reflect.ValueOf(t.serviceCreateFun)
		result := rfun.Call([]reflect.Value{reflect.ValueOf(transport), reflect.ValueOf(t.ProtocolFactory)})
		if len(result) != 1 {
			return nil, errors.New("func must return 1 result")
		}
		return &ServiceWrapper{service: result[0].Interface(), transport: transport}, err
	}

}
コード例 #27
0
ファイル: main.go プロジェクト: y-okubo/thrift-test
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))
}
コード例 #28
0
ファイル: reqjesgoo.go プロジェクト: ifzz/seller_adptor
func (this *ReqJesgooModule) Init(global_conf *context.GlobalContext) (err error) {

	err = this.redis.Init(global_conf)
	if err != nil {
		utils.FatalLog.Write("init redis fail, err[%s]", err.Error())
		return
	}

	this.host = global_conf.JesgooBs.Host
	this.port = global_conf.JesgooBs.Port
	this.timeout = global_conf.JesgooBs.Timeout

	this.pool = &connpool.ConnPool{
		Dial: func() (interface{}, error) {
			transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
			protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
			transport, _ := thrift.NewTSocket(net.JoinHostPort(this.host, this.port))
			usetransport := transportFactory.GetTransport(transport)
			client := ui2bs.NewBSServiceClientFactory(usetransport, protocolFactory)
			err := client.Transport.Open()
			if err != nil {
				utils.FatalLog.Write("new jesgoo bs client fail , [%s]", err.Error())
				return nil, err
			}
			return client, err
		},
		Close: func(c interface{}) error {
			err := c.(*ui2bs.BSServiceClient).Transport.Close()
			return err
		},
		Alive: func(c interface{}) bool {
			_, err := c.(*ui2bs.BSServiceClient).Ping()
			if err != nil {
				utils.DebugLog.Write("transport is closed")
				return false
			}
			return true
		},
		MaxIdle: 1024,
	}
	return
}
コード例 #29
0
ファイル: person.go プロジェクト: dynastymasra/GoGinThrift
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
}
コード例 #30
0
ファイル: person.go プロジェクト: dynastymasra/GoGinThrift
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
}