Exemple #1
0
func main() {
	config, args := skynet.GetClientConfig()
	client := client.NewClient(config)

	service := client.GetService("Fibonacci", "", "", "")

	if len(args) == 0 {
		fmt.Printf("Usage: %s <positive number>*\n", args[0])
		return
	}

	for _, arg := range args[1:] {
		index, err := strconv.Atoi(arg)
		if err != nil {
			panic(err)
		}
		req := fibonacci.Request{
			Index: index,
		}
		resp := fibonacci.Response{}
		err = service.Send(nil, "Index", req, &resp)
		if err != nil {
			fmt.Println(err)
		} else {
			fmt.Printf("%d -> %d\n", index, resp.Value)
		}
	}
}
Exemple #2
0
func main() {
	config, _ := skynet.GetClientConfig()

	var err error

	config.Log = skynet.NewConsoleSemanticLogger("TestServiceClient", os.Stderr)

	client := client.NewClient(config)

	// This will not fail if no services currently exist, as
	// connections are created on demand this saves from chicken and
	// egg issues with dependencies between services
	service := client.GetService("TestService", "", "", "")
	// (any version, any region, any host)

	// This on the other hand will fail if it can't find a service to
	// connect to
	in := map[string]interface{}{
		"data": "Upcase me!!",
	}
	out := map[string]interface{}{}
	err = service.Send(nil, "Upcase", in, &out)

	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(out["data"].(string))
}
Exemple #3
0
func main() {
	config := &skynet.ClientConfig{
		DoozerConfig: &skynet.DoozerConfig{},
	}

	flagset := flag.NewFlagSet("sleepclient", flag.ContinueOnError)

	skynet.FlagsForClient(config, flagset)

	req := sleeper.Request{
		Message: "Hello!",
	}

	var (
		retry  time.Duration
		giveup time.Duration
	)

	flagset.DurationVar(&req.Duration, "sleepfor", 5*time.Second,
		"how long to sleep")
	flagset.BoolVar(&req.ExitWhenDone, "exit", false,
		"have the service call os.Exit(0) when finished sleeping")
	flagset.BoolVar(&req.PanicWhenDone, "panic", false,
		"have the service panic when finished sleeping")
	flagset.BoolVar(&req.UnregisterWhenDone, "unregister", false,
		"have the service unregister when finished sleeping")
	flagset.BoolVar(&req.UnregisterHalfwayThrough, "unregister-halfway", false,
		"have the service unregister half-way through the sleep")
	flagset.DurationVar(&retry, "retry", time.Second,
		"how long to wait before trying again")
	flagset.DurationVar(&giveup, "giveup", 5*time.Second,
		"how long to wait before giving up")

	flagset.Parse(os.Args[1:])

	config.MaxConnectionsToInstance = 5

	client := client.NewClient(config)

	service := client.GetService("Sleeper", "", "", "")

	service.SetTimeout(retry, giveup)

	resp := sleeper.Response{}

	start := time.Now()

	err := service.Send(nil, "Sleep", req, &resp)

	duration := time.Now().Sub(start).Nanoseconds()

	fmt.Printf("request took %dns\n", duration)

	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Printf("%s -> %s\n", req.Message, resp.Message)
	}
}
Exemple #4
0
func main() {
	config, _ := skynet.GetClientConfig()
	client := client.NewClient(config)

	service := client.GetService("TutorialService", "1", "Development", "")

	req := &TutorialRequest{
		Value: 1,
	}

	resp := &TutorialResponse{}

	err := service.Send(nil, "AddOne", req, resp)

	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println(resp.Value)
	}
}