Exemple #1
0
func main() {
	flag.Parse()

	var cl client.Client
	if *trans == "http" {
		zk := zookeeper.New([]string{*zkHost})
		lb := loadbalancer.New(zk, loadbalancer.NewRoundRobin())

		cl = client.New("upper", jsonrpc.New(http.New()), lb, extension.NewTimeoutExt(1*time.Second))
	} else if *trans == "amqp" {
		cl = client.New("upper", jsonrpc.New(amqp.New(*rmqHost)), extension.NewTimeoutExt(2*time.Second))
	} else {
		panic("unknown transport")
	}

	c := time.Tick(1 * time.Second)
	i := 0
	for _ = range c {
		text := fmt.Sprintf("foo_%d", i)
		result, err := cl.Call("upper.upper", text)

		if err != nil {
			fmt.Printf("Error: %s\n", err)
		} else {
			fmt.Printf("%s\n", result.(string))
		}
		i++
	}
}
Exemple #2
0
func main() {
	flag.Parse()

	zkAnnouncer := zookeeper.New(
		[]string{*zkHost},
	)

	httpServ := server.New(jsonrpc.New(http.New()))
	httpServ.Register("upper", upperService{}, ms...)

	go func() {
		if err := httpServ.ServeAndAnnounce(zkAnnouncer); err != nil {
			panic(err)
		}
	}()

	amqpServ := server.New(jsonrpc.New(amqp.New(*rmqHost)))
	amqpServ.Register("upper", upperService{}, ms...)

	amqpServ.Serve()
}