Ejemplo n.º 1
0
func main() {
	c := make(chan os.Signal, 1)

	config, _ := skynet.GetClientConfigFromFlags()

	var err error
	config.Log = skynet.NewConsoleLogger(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))

	watchSignals(c)
}
Ejemplo n.º 2
0
func main() {
	config, _ := skynet.GetClientConfigFromFlags()
	client := client.NewClient(config)

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

	service.SetTimeout(1*time.Second, 10*time.Second)

	req := sleeper.Request{
		Message:  "Hello!",
		Duration: 5 * time.Second,
	}
	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)
	}
}
Ejemplo n.º 3
0
func NewFibonacci() (f *Fibonacci) {
	f = new(Fibonacci)

	f.cconfig, _ = skynet.GetClientConfigFromFlags()
	f.client = client.NewClient(f.cconfig)

	f.cache = map[int]chan uint64{
		0: make(chan uint64, 1),
		1: make(chan uint64, 1),
	}
	f.cache[0] <- 0
	f.cache[1] <- 1

	return
}
Ejemplo n.º 4
0
func getDaemonServiceClient(q *client.Query) (c *client.Client, service *client.ServiceClient) {
	config, _ := skynet.GetClientConfigFromFlags(os.Args...)

	config.Log = skynet.NewConsoleLogger(os.Stderr)

	c = client.NewClient(config)

	registered := true
	query := &client.Query{
		DoozerConn: c.DoozerConn,
		Service:    "SkynetDaemon",
		//Host:       "127.0.0.1",
		Registered: &registered,
	}
	service = c.GetServiceFromQuery(query)
	return
}
Ejemplo n.º 5
0
func main() {
	config, args := skynet.GetClientConfigFromFlags()
	client := client.NewClient(config)

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

	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)
		}
	}
}