goczmq
goczmq copied to clipboard
issues with setidentity
Hello,
I think it would be really helpful to point out in the documentation that you need to set the identity of the socket before you connect.
The following will not set the correct identity dealer, err := goczmq.NewDealer("tcp://127.0.0.1:5555") dealer.SetIdentity("magic")
However this does work: dealer := goczmq.NewSock(goczmq.Dealer) dealer.SetIdentity("magic") err = dealer.Connect("tcp://127.0.0.1:5555")
Also, if you could provide example on how to setoptions via NewDealer that would be awesome. Thanks much.
Thanks for filing the issue! It's always great to hear about cases that are non obvious to other people. I appreciate the feedback!
I met the same issue, thank you @Irooniam
This doesn't seem correct, at least not anymore perhaps. Go errors out on building this code. Whats the recommended method?
func (c *czmqSocketClient) connect() (err error) {
addr := fmt.Sprintf("tcp://%s:%d", c.masterHost, c.masterPort)
dealer := goczmq.NewSock(goczmq.Dealer)
dealer.SetIdentity(c.identity)
err = dealer.Connect(addr)
if err != nil {
return err
}
c.dealerSocket = dealer
log.Printf("Boomer is connected to master(%s) press Ctrl+c to quit.\n", addr)
go c.recv()
go c.send()
return nil
}
dealer.SetIdentity undefined (type *goczmq.Sock has no field or method SetIdentity)
Figured it out for the newer version.
sockoptions := goczmq.SockSetIdentity(c.identity)
dealer.SetOption(sockoptions)
Some socket options needing to be set before a bind or connect on a socket are things that definitely tripped me up when I first started using ZeroMQ, even before I started writing GoCZMQ. I think it's a great suggestion to make it more visible in the documentation and can do so.
@gclair note that outside of the new socket options in my latest release your example has one other problem: ZeroMQ sockets are not thread safe. You should not spawn a receive or a send via a go routine. While it may sometimes work, it is almost guaranteed to eventually cause a problem.
You should not spawn a receive or a send via a go routine
Oops, thanks for the heads up. Because Sock.RecvFrame is a blocking call, how can I read and write in a single goroutine?
@myzhan take a look at the poller - https://github.com/zeromq/goczmq/blob/master/poller.go https://github.com/zeromq/goczmq/blob/master/poller_test.go
@taotetek Thanks, if I put reading and writing in a goroutine, I can select on a time.Ticker to do polling.