Created
February 14, 2017 05:52
-
-
Save zwh8800/55cb6a7db96106af4822b6dbb96729ee to your computer and use it in GitHub Desktop.
zmq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
zmq "github.com/pebbe/zmq4" | |
uuid "github.com/satori/go.uuid" | |
) | |
func main() { | |
reportRequest, err := zmq.NewSocket(zmq.REP) | |
if err != nil { | |
panic(err) | |
} | |
if err := reportRequest.Connect("tcp://localhost:13378"); err != nil { | |
panic(err) | |
} | |
workerId := uuid.NewV4().String() | |
for { | |
data, err := reportRequest.Recv(0) | |
if err != nil { | |
panic(err) | |
} | |
log.Println(data) | |
if _, err := reportRequest.Send(fmt.Sprintln("workerId:", workerId), 0); err != nil { | |
panic(err) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"time" | |
zmq "github.com/pebbe/zmq4" | |
) | |
func main() { | |
reportRequest, err := zmq.NewSocket(zmq.REQ) | |
if err != nil { | |
panic(err) | |
} | |
if err := reportRequest.Bind("tcp://*:13378"); err != nil { | |
panic(err) | |
} | |
clientMap := make(map[string]bool) | |
for { | |
for i := 0; len(clientMap) == 0 || i < len(clientMap); i++ { | |
if _, err := reportRequest.Send("need report", 0); err != nil { | |
panic(err) | |
} | |
log.Println("send ok") | |
data, err := reportRequest.Recv(0) | |
if err != nil { | |
panic(err) | |
} | |
log.Println(data) | |
clientMap[data] = true | |
} | |
time.Sleep(1 * time.Second) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment