Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issues with setidentity #250

Open
Irooniam opened this issue Nov 30, 2018 · 8 comments
Open

issues with setidentity #250

Irooniam opened this issue Nov 30, 2018 · 8 comments

Comments

@Irooniam
Copy link

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.

@taotetek
Copy link
Contributor

taotetek commented Dec 7, 2018

Thanks for filing the issue! It's always great to hear about cases that are non obvious to other people. I appreciate the feedback!

@myzhan
Copy link

myzhan commented Feb 11, 2019

I met the same issue, thank you @Irooniam

@gclair
Copy link

gclair commented Jul 13, 2019

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)

@gclair
Copy link

gclair commented Jul 13, 2019

Figured it out for the newer version.

        sockoptions := goczmq.SockSetIdentity(c.identity)
        dealer.SetOption(sockoptions)

@taotetek
Copy link
Contributor

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.

@myzhan
Copy link

myzhan commented Jul 15, 2019

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?

@taotetek
Copy link
Contributor

@myzhan
Copy link

myzhan commented Jul 22, 2019

@taotetek Thanks, if I put reading and writing in a goroutine, I can select on a time.Ticker to do polling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants