Esempio n. 1
0
func main() {
	scribeService := new(scribeServiceImplementation)
	rpc.RegisterName("Thrift", &scribe.ScribeServer{Implementation: scribeService})
	flag.IntVar(&port, "p", 1463, "Scribe Listen Port")
	flag.StringVar(&kafka_hostname, "o", "localhost:9092", "host:port string for the kafka server")
	flag.IntVar(&partition, "r", 1, "partition to publish to")
	flag.IntVar(&buffer_size, "s", 10, "Buffer Size")
	flag.IntVar(&buffer_time, "t", 10, "Buffer Time")

	flag.Parse()

	fmt.Printf("Quiet! I'm trying to listen to port %d and send to kafka at %s", port, kafka_hostname)
	ln, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
	if err != nil {
		log.Println(err)
	}
	for {
		conn, err := ln.Accept()
		if err != nil {
			fmt.Printf("ERROR: %+v\n", err)
			continue
		}
		fmt.Printf("New connection %+v\n", conn)
		go rpc.ServeCodec(thrift.NewServerCodec(thrift.NewFramedReadWriteCloser(conn, 0), thrift.NewBinaryProtocol(true, false)))
	}
}
func main() {
	flag.IntVar(&port, "p", 1463, "Scribe Port")
	flag.IntVar(&count, "c", 100, "Test messages")
	flag.StringVar(&host, "h", "localhost", "Scribe Host")
	flag.StringVar(&category, "c", "category", "Scribe Category")
	flag.Parse()
	message, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		panic(err)
	}
	fmt.Println(os.Args)
	conn, err := net.Dial("tcp", fmt.Sprintf("%s:1463", host))
	if err != nil {
		panic(err)
	}

	client := thrift.NewClient(thrift.NewFramedReadWriteCloser(conn, 0), thrift.NewBinaryProtocol(true, false), false)
	scr := scribe.ScribeClient{Client: client}
	arr := make([]*scribe.LogEntry, count)
	for i := 0; i < count; i++ {
		arr[i] = &scribe.LogEntry{category, string(message)}
	}
	res, err := scr.Log(arr)
	if err != nil {
		panic(err)
	}

	fmt.Printf("Response: %+v\n", res)
}
Esempio n. 3
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

}
Esempio n. 4
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)
	}
}
Esempio n. 5
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)
}
Esempio n. 6
0
func main() {
	conn, err := net.Dial("tcp", "127.0.0.1:1463")
	if err != nil {
		panic(err)
	}

	client := thrift.NewClient(thrift.NewFramedReadWriteCloser(conn, 0), thrift.NewBinaryProtocol(true, false), 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)
}
Esempio n. 7
0
func main() {
	scribeService := new(scribeServiceImplementation)
	rpc.RegisterName("Thrift", &scribe.ScribeServer{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)
		go rpc.ServeCodec(thrift.NewServerCodec(thrift.NewFramedReadWriteCloser(conn, 0), thrift.NewBinaryProtocol(true, false)))
	}
}
Esempio n. 8
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)
		}
	}
}