Exemplo n.º 1
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()
}
Exemplo n.º 2
0
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
}
Exemplo n.º 3
0
func (self *FlumeClient) clientConn() error {
	//使用非阻塞io来传输
	self.transport = self.transportFactory.GetTransport(self.tsocket)
	self.thriftclient = flume.NewThriftSourceProtocolClientFactory(self.transport, self.protocolFactory)
	if err := self.transport.Open(); nil != err {
		log.Printf("FLUME_CLIENT|CREATE THRIFT CLIENT|FAIL|%s|%s", self.HostPort(), err)
		return err
	}
	return nil
}