I'm trying a simple code:
package main
import (
"fmt"
zmq "github.com/alecthomas/gozmq"
)
func main() {
context, _ := zmq.NewContext()
defer context.Close()
// Socket to receive messages on
receiver, _ := context.NewSocket(zmq.PULL)
defer receiver.Close()
receiver.Connect("tcp://localhost:5557")
// Process tasks forever
for {
msgbytes, _ := receiver.Recv(0)
fmt.Println("received")
fmt.Println(string(msgbytes))
}
}
In NodeJS I send messages like this:
console.log(payload);
sender.send(JSON.stringify(payload));
I can see the json in the console, so sender.sen() is actually sending things. Also, the output from the .go program for each payload is:
received
[]
received
[]
There's no output. I've searched the GoDocs for the Recv method and there's no separation like recv_json, recv_message, etc like in other languages, it's all bytes. So what's happening? I'm sending a string because it's sent as stringfy, right?
UPDATE
As Nehal said below, I changed the import statement to the official rep, and this is the new code:
package main
import (
"fmt"
zmq "gopkg.in/zeromq/goczmq.v4"
)
func main() {
// Socket to receive messages on
receiver, _ := zmq.NewPull("tcp://*:5557")
defer receiver.Destroy()
// Process tasks forever
for {
request, _ := receiver.RecvMessage()
fmt.Println("received")
fmt.Println(request)
}
}
But this time 'received' isn't even printed, it seems that no message is being received at all