コード例 #1
0
ファイル: client.go プロジェクト: pengzhai/tchannel
func main() {
	// Create a TChannel.
	ch, err := tchannel.NewChannel("keyvalue-client", nil)
	if err != nil {
		log.Fatalf("Failed to create tchannel: %v", err)
	}

	// Set up Hyperbahn client.
	config := hyperbahn.Configuration{InitialNodes: os.Args[1:]}
	if len(config.InitialNodes) == 0 {
		log.Fatalf("No Autobahn nodes to connect to given")
	}
	hyperbahn.NewClient(ch, config, nil)

	thriftClient := thrift.NewClient(ch, "keyvalue", nil)
	client := keyvalue.NewTChanKeyValueClient(thriftClient)
	adminClient := keyvalue.NewTChanAdminClient(thriftClient)

	// Read commands from the command line and execute them.
	scanner := bufio.NewScanner(os.Stdin)
	printHelp()
	fmt.Printf("> ")
	for scanner.Scan() {
		parts := strings.Split(scanner.Text(), " ")
		if parts[0] == "" {
			continue
		}
		switch parts[0] {
		case "help":
			printHelp()
		case "get":
			if len(parts) < 2 {
				printHelp()
				break
			}
			get(client, parts[1])
		case "set":
			if len(parts) < 3 {
				printHelp()
				break
			}
			set(client, parts[1], parts[2])
		case "user":
			if len(parts) < 2 {
				printHelp()
				break
			}
			curUser = parts[1]
		case "clearAll":
			clear(adminClient)
		default:
			log.Printf("Unsupported command %q\n", parts[0])
		}
		fmt.Print("> ")
	}
	scanner.Text()
}
コード例 #2
0
// NewZipkinTraceReporter returns a zipkin trace reporter that submits span to tcollector service.
func NewZipkinTraceReporter(ch *tc.Channel) *ZipkinTraceReporter {
	thriftClient := thrift.NewClient(ch, tcollectorServiceName, nil)
	client := tcollector.NewTChanTCollectorClient(thriftClient)
	// create the goroutine method to actually to the submit Span.
	reporter := &ZipkinTraceReporter{
		tchannel: ch,
		client:   client,
		c:        make(chan zipkinData, chanBufferSize),
		logger:   ch.Logger(),
	}
	go reporter.zipkinSpanWorker()
	return reporter
}
コード例 #3
0
ファイル: main.go プロジェクト: shawnburke/tchannel
func runClient2(hyperbahnService string, addr net.Addr) error {
	tchan, err := tchannel.NewChannel("client2", optsFor("client2"))
	if err != nil {
		return err
	}
	tchan.Peers().Add(addr.String())
	tclient := thrift.NewClient(tchan, hyperbahnService, nil)
	client := gen.NewTChanSecondClient(tclient)

	go func() {
		for {
			ctx, cancel := thrift.NewContext(time.Second)
			client.Test(ctx)
			cancel()
			time.Sleep(100 * time.Millisecond)
		}
	}()
	return nil
}
コード例 #4
0
ファイル: main.go プロジェクト: shawnburke/tchannel
func runClient1(hyperbahnService string, addr net.Addr) error {
	tchan, err := tchannel.NewChannel("client1", optsFor("client1"))
	if err != nil {
		return err
	}
	tchan.Peers().Add(addr.String())
	tclient := thrift.NewClient(tchan, hyperbahnService, nil)
	client := gen.NewTChanFirstClient(tclient)

	go func() {
		for {
			ctx, cancel := thrift.NewContext(time.Second)
			res, err := client.Echo(ctx, "Hi")
			log.Println("Echo(Hi) = ", res, ", err: ", err)
			log.Println("AppError = ", client.AppError(ctx))
			cancel()
			time.Sleep(100 * time.Millisecond)
		}
	}()
	return nil
}
コード例 #5
0
// NewZipkinTraceReporter returns a zipkin trace reporter that submits span to tcollector service.
func NewZipkinTraceReporter(ch *tc.Channel) *ZipkinTraceReporter {
	thriftClient := thrift.NewClient(ch, tcollectorServiceName, nil)
	client := tcollector.NewTChanTCollectorClient(thriftClient)
	return &ZipkinTraceReporter{tchannel: ch, client: client}
}