本文整理汇总了Golang中github.com/alecthomas/gozmq.Socket.RecvMultipart方法的典型用法代码示例。如果您正苦于以下问题:Golang Socket.RecvMultipart方法的具体用法?Golang Socket.RecvMultipart怎么用?Golang Socket.RecvMultipart使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/alecthomas/gozmq.Socket
的用法示例。
在下文中一共展示了Socket.RecvMultipart方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Forward
// A blocking function that will infinitely forward multi-part messages between two zmq.Sockets
func Forward(a, b zmq.Socket) {
for {
parts, err := a.RecvMultipart(0)
if err != nil {
log.Println("Error receiving message on frontend broker", err)
}
err = b.SendMultipart(parts, 0)
if err != nil {
log.Println("Error sending message on backend broker", err)
}
// log.Println("Brokered message:", Stringify(parts))
}
}
示例2: dump
func dump(sink zmq.Socket) {
parts, err := sink.RecvMultipart(0)
if err != nil {
fmt.Println(err)
}
for _, msgdata := range parts {
is_text := true
fmt.Printf("[%03d] ", len(msgdata))
for _, char := range msgdata {
if char < 32 || char > 127 {
is_text = false
}
}
if is_text {
fmt.Printf("%s\n", msgdata)
} else {
fmt.Printf("%X\n", msgdata)
}
}
}
示例3: ReadPb
// ReadPb sends any protobuf along a ZMQ socket. This makes sure to bundle our
// type identifier at the beginning of the message.
func ReadPb(sock *zmq.Socket, timeout int) ([]byte, interface{}, error) {
if timeout > 0 {
if !WaitForRecv(sock, timeout) {
return nil, nil, errors.New("recv timeout")
}
}
rresp, err := sock.RecvMultipart(0)
if err != nil {
return nil, nil, err
}
// If we got a remote address, keep it.
var remote []byte
if len(rresp) > 1 {
remote = rresp[0] // Remote address.
}
resp := rresp[len(rresp)-1]
var pb interface{}
switch resp[0] {
case 1:
pb = &Command{}
case 2:
pb = &StillAlive{}
case 3:
pb = &CommandFinished{}
case 4:
pb = &CommandOutput{}
default:
return nil, nil, errors.New(fmt.Sprintf("unknown packet type: %d", resp[0]))
}
err = proto.Unmarshal(resp[1:], pb.(proto.Message))
if err != nil {
return nil, nil, err
}
return remote, pb, nil
}