func snapshots(socket *zmq.Socket, srv *clonesrv_t) (err error) { msg, err := socket.RecvMessage(0) if err != nil { return } identity := msg[0] // Request is in second frame of message request := msg[1] if request != "ICANHAZ?" { err = errors.New("E: bad request, aborting") return } subtree := msg[2] // Send state socket to client for _, kvmsg := range srv.kvmap { if key, _ := kvmsg.GetKey(); strings.HasPrefix(key, subtree) { socket.Send(identity, zmq.SNDMORE) kvmsg.Send(socket) } } // Now send END message with sequence number log.Println("I: sending shapshot =", srv.sequence) socket.Send(identity, zmq.SNDMORE) kvmsg := kvmsg.NewKvmsg(srv.sequence) kvmsg.SetKey("KTHXBAI") kvmsg.SetBody(subtree) kvmsg.Send(socket) return }
// send a message to the zmq PUB socket func sendMessage(reqsocket zmq.Socket, e envelope) { serialized_envelope, _ := json.Marshal(e) reqsocket.Send(string(serialized_envelope), 0) // wait for a reply reqsocket.Recv(0) }