コード例 #1
0
ファイル: mdclient.go プロジェクト: JeremyOT/zmq4
func main() {
	var verbose bool
	if len(os.Args) > 1 && os.Args[1] == "-v" {
		verbose = true
	}
	session, _ := mdapi.NewMdcli("tcp://localhost:5555", verbose)

	count := 0
	for ; count < 100000; count++ {
		_, err := session.Send("echo", "Hello world")
		if err != nil {
			log.Println(err)
			break //  Interrupt or failure
		}
	}
	fmt.Printf("%d requests/replies processed\n", count)
}
コード例 #2
0
ファイル: mmiecho.go プロジェクト: gallir/zmq4
func main() {
	var verbose bool
	if len(os.Args) > 1 && os.Args[1] == "-v" {
		verbose = true
	}
	session, _ := mdapi.NewMdcli("tcp://localhost:5555", verbose)

	//  This is the service we want to look up
	request := "echo"

	//  This is the service we send our request to
	reply, err := session.Send("mmi.service", request)

	if err == nil {
		fmt.Println("Lookup echo service:", reply[0])
	} else {
		fmt.Println("E: no response from broker, make sure it's running")
	}
}
コード例 #3
0
ファイル: titanic.go プロジェクト: gallir/zmq4
func ServiceSuccess(uuid string) bool {
	// If reply already exists, treat as successful
	_, err := os.Stat(ReplyFilename(uuid))
	if err == nil {
		return true
	}

	//  Load request message, service will be first frame
	data, err := ioutil.ReadFile(RequestFilename(uuid))

	//  If the client already closed request, treat as successful
	if err != nil {
		return true
	}

	request := strings.Split(string(data), "\n")

	service_name := request[0]
	request = request[1:]

	//  Create MDP client session with short timeout
	client, err := mdapi.NewMdcli("tcp://localhost:5555", false)
	client.SetTimeout(time.Second) //  1 sec
	client.SetRetries(1)           //  only 1 retry

	//  Use MMI protocol to check if service is available
	mmi_reply, err := client.Send("mmi.service", service_name)
	if err != nil || mmi_reply[0] != "200" {
		return false
	}

	reply, err := client.Send(service_name, request...)
	if err != nil {
		return false
	}

	file, err := os.Create(ReplyFilename(uuid))
	fmt.Fprint(file, strings.Join(reply, "\n"))
	file.Close()

	return true

}
コード例 #4
0
ファイル: ticlient.go プロジェクト: JeremyOT/zmq4
func main() {
	var verbose bool
	if len(os.Args) > 1 && os.Args[1] == "-v" {
		verbose = true
	}
	session, _ := mdapi.NewMdcli("tcp://localhost:5555", verbose)

	//  1. Send 'echo' request to Titanic
	reply, err := ServiceCall(session, "titanic.request", "echo", "Hello world")
	if err != nil {
		fmt.Println(err)
		return
	}

	var uuid string
	if err == nil {
		uuid = reply[0]
		fmt.Println("I: request UUID", uuid)
	}

	time.Sleep(100 * time.Millisecond)

	//  2. Wait until we get a reply
	for {
		reply, err := ServiceCall(session, "titanic.reply", uuid)
		if err == nil {
			fmt.Println("Reply:", reply[0])

			//  3. Close request
			ServiceCall(session, "titanic.close", uuid)
			break
		} else {
			fmt.Println("I: no reply yet, trying again...")
			time.Sleep(5 * time.Second) //  Try again in 5 seconds
		}
	}
}