Exemple #1
0
func (l *ScribeLogger) connect() error {
	if l.client != nil {
		return nil
	}

	var conn net.Conn
	var err error
	//try to conect 3 times
	for reconns := 0; reconns < _MAX_RETRIES; reconns++ {
		conn, err = net.Dial("tcp", l.addr)
		if err != nil {
			if reconns >= _MAX_RETRIES-1 {
				log.Printf("ERROR: Could not connect to scribe server: %s\n", err)
				return err
			}
			time.Sleep(100 * time.Millisecond) //wait a bit before retrying
		} else {
			break
		}

	}

	transport := thrift.NewTransport(thrift.NewFramedReadWriteCloser(conn, 0), thrift.BinaryProtocol)
	client := thrift.NewClient(transport, false)
	l.client = &scribe.ScribeClient{Client: client}
	l.enabled = true
	return nil

}
Exemple #2
0
func runServer(port string) {
	// Set processor
	rpc.RegisterName("Thrift", &echo.EchoServer{Implementation: new(echoHandler)})
	ln, _ := net.Listen("tcp", port)

	for {
		conn, _ := ln.Accept()
		go func(c net.Conn) {
			t := thrift.NewTransport(thrift.NewFramedReadWriteCloser(c, 0), thrift.BinaryProtocol)
			rpc.ServeCodec(thrift.NewServerCodec(t))
		}(conn)
	}
}
Exemple #3
0
// Run runs the handler main loop
func (s *Scribe) Run() {
	server := fmt.Sprintf("%s:%d", s.endpoint, s.port)
	conn, err := net.Dial("tcp", server)

	if err != nil {
		s.log.Errorf("Failed to connect to %s. Error: %s", server, err.Error())

	} else {
		t := thrift.NewTransport(thrift.NewFramedReadWriteCloser(conn, 0), thrift.BinaryProtocol)
		client := thrift.NewClient(t, false)
		s.scribeClient = &scribe.ScribeClient{Client: client}
	}

	s.run(s.emitMetrics)
}
Exemple #4
0
func main() {
	conn, err := net.Dial("tcp", "127.0.0.1:1463")
	if err != nil {
		panic(err)
	}

	t := thrift.NewTransport(thrift.NewFramedReadWriteCloser(conn, 0), thrift.BinaryProtocol)
	client := thrift.NewClient(t, false)
	scr := scribe.ScribeClient{Client: client}
	res, err := scr.Log([]*scribe.LogEntry{{"category", "message"}})
	if err != nil {
		panic(err)
	}

	fmt.Printf("Response: %+v\n", res)
}
Exemple #5
0
func main() {
	scribeService := new(scribeServiceImplementation)
	rpc.RegisterName("Thrift", &scribe.ScribeServer{Implementation: scribeService})

	ln, err := net.Listen("tcp", ":1463")
	if err != nil {
		panic(err)
	}
	for {
		conn, err := ln.Accept()
		if err != nil {
			fmt.Printf("ERROR: %+v\n", err)
			continue
		}
		fmt.Printf("New connection %+v\n", conn)
		t := thrift.NewTransport(thrift.NewFramedReadWriteCloser(conn, 0), thrift.BinaryProtocol)
		go rpc.ServeCodec(thrift.NewServerCodec(t))
	}
}
Exemple #6
0
func handleClient(addr string, num int) {
	// Open independent client connection
	conn, _ := net.Dial("tcp", addr)
	t := thrift.NewTransport(thrift.NewFramedReadWriteCloser(conn, 0), thrift.BinaryProtocol)
	client := thrift.NewClient(t, false)
	defer client.Close()
	ec := echo.EchoClient{Client: client}

	// UUID
	uid := uuid.NewV4().String()

	for i := 0; i < num; i++ {
		// Make thrift call and increment atomic count
		txt := uid + strconv.Itoa(i)
		ret, _ := ec.Echo(&echo.Message{Text: &txt})
		if txt == ret {
			atomic.AddUint64(&count, 1)
		}
	}
}