Esempio n. 1
0
func callRpcService(service string, operation string, async bool, failOnErr bool, cr *myStartup.GetUserDataRequest, rep *myStartup.GetUserDataResponse) (err os.Error) {
	defer skylib.CheckError(&err)

	rpcClient, err := skylib.GetRandomClientByService(service)
	if err != nil {
		log.Println("No service provides", service)
		if failOnErr {
			return skylib.NewError(skylib.NO_CLIENT_PROVIDES_SERVICE, service)
		} else {
			return nil
		}
	}
	name := service + operation
	if async {
		go rpcClient.Call(name, cr, rep)
		log.Println("Called service async", name)
		return nil
	}
	log.Println("Calling : " + name)
	err = rpcClient.Call(name, cr, rep)
	if err != nil {
		log.Println("failed connection, retrying", err)
		// get another one and try again!
		rpcClient, err := skylib.GetRandomClientByService(service)
		err = rpcClient.Call(name, cr, rep)
		if err != nil {
			return skylib.NewError(err.String(), name)
		}
	}
	log.Println("Called service operation sync", name)
	return nil
}
Esempio n. 2
0
func main() {
	flag.Parse()
	skylib.NewAgent().Start()
	service := "MyRandomService"
	client, _ := skylib.GetRandomClientByService(service)
	request := rand.Intn(10) + 1
	println("Request:", request)
	var response string = "default" // to prove it has changed
	client.Call(service+".RandString", request, &response)
	println("Reponse:", response)
	println("Done.")
}
Esempio n. 3
0
// Call the RPC service on the router to process the GetUserDataRequest.
func submitGetUserDataRequest(cr *myStartup.GetUserDataRequest) (*myStartup.GetUserDataResponse, os.Error) {
	var GetUserDataResponse *myStartup.GetUserDataResponse

	service := "RouteService"
	client, err := skylib.GetRandomClientByService(service)
	if err != nil {
		if GetUserDataResponse == nil {
			GetUserDataResponse = &myStartup.GetUserDataResponse{}
		}
		GetUserDataResponse.Errors = append(GetUserDataResponse.Errors, err.String())
		return GetUserDataResponse, err
	}
	err = client.Call(service+".RouteGetUserDataRequest", cr, &GetUserDataResponse)
	if err != nil {
		if GetUserDataResponse == nil {
			GetUserDataResponse = &myStartup.GetUserDataResponse{}

		}
		GetUserDataResponse.Errors = append(GetUserDataResponse.Errors, err.String())
	}

	return GetUserDataResponse, nil
}