Example #1
0
func getServiceDesc(SID string) (reply string, err error) {
	//  Get description of requested service
	service, isPresent := services[SID]
	//  Service not available
	if !isPresent {
		err = errors.New("NotAvailable")
		reply = "NotAvailable"
		return
	}

	//  Get heartbeat of requested service
	var heartbeat []string
	heartbeat, err = msg.SendRequest(service, msg.PPP_HEARTBEAT, "")
	heartbeat_state := time.Now().String()
	if err != nil {
		heartbeat_state = fmt.Sprintf("%s", err)
	}
	if len(heartbeat) < 1 || heartbeat[0] != msg.PPP_READY {
		err = errors.New("Error:ServiceNotReady")
		heartbeat_state = fmt.Sprintf("%s", err)
	}
	service.Heartbeat_state = heartbeat_state
	services[SID] = service

	//  Service located
	reply = string(encodeTOJSON(service))
	return
}
Example #2
0
func main() {
	for request_nbr := 0; request_nbr != 10; request_nbr++ {
		message := fmt.Sprintf("Hello %d", request_nbr)
		reply, err := msg.SendRequest(services["hello"], "hello", message)
		if err != nil {
			log.Println("Whoops! ", err)
			reply, err = msg.SendRequest(services["lookup"], "lookup", "hello")
			if err != nil {
				log.Println(err)
				continue
			}
			for i := range reply {
				registerService(reply[i], "hello")
			}
			continue
		}
		fmt.Println("\tSpliced Received: ", reply)
		fmt.Println("\tOn to the next...")
	}
}
Example #3
0
//  Initialize by setting address and registering service with directory service
func init() {
	myservices["hello"] = doHelloWorld
	myservices[msg.PPP_HEARTBEAT] = msg.ProcessHeartBeat
	allowedbinders = "tcp://*:5560"
	mydescription = msg.NewService("hello", "Hello Service", "tcp://localhost:5560", "hello", "REP")
	//  All I need to know are the details of the lookup service
	services["lookup"] = msg.NewService("lookup", "LookUp Service", "tcp://localhost:5569", "lookup", "REP")

	fmt.Println("Registering service...")
	reply, err := msg.SendRequest(services["lookup"], "register", string(encodeTOJSON(mydescription)))
	if err != nil {
		log.Println(err)
	}
	fmt.Println("\t", reply)
}
Example #4
0
//  Init function requests for all services that the client will require
func init() {
	servicesFileName = "dcservicelist.json"
	servicesReq = append(servicesReq, "hello")
	//  All I need to know are the details of the lookup service
	services["lookup"] = msg.NewService("lookup", "LookUp Service", "tcp://localhost:5569", "lookup", "REP")

	//  Get my service list
	getServiceList()

	//  Get all services I require that are not listed in my service list
	for _, serviceReq := range servicesReq {
		if _, isListed := services[serviceReq]; isListed == false {
			reply, err := msg.SendRequest(services["lookup"], "lookup", serviceReq)
			if err != nil {
				panic(err)
			}
			for i := range reply {
				registerService(reply[i], serviceReq)
			}
		}
	}
}