pebbe / zmq4

A Go interface to ZeroMQ version 4
BSD 2-Clause "Simplified" License
1.17k stars 163 forks source link

Feature Request: ZMQ_RADIO/ZMQ_DISH #87

Open iamthebot opened 8 years ago

iamthebot commented 8 years ago

The new RADIO/DISH sockets were merged into libzmq master a little over a month ago. With them comes the ability to use UDP as a transport. This is particularly important for cases that desire low latency and drop stale data as a policy.

test_udp.cpp in the libzmq tests directory shows sample usage: https://github.com/zeromq/libzmq/blob/master/tests/test_udp.cpp

pebbe commented 8 years ago

Implemented sockets and test in branch devel.

Subject to change. This will not be merged into master until the official release of ZeroMQ version 4.2.

Any comments on this implementation are welcome. See especially the new functions RecvWithOpts and RecvBytesWithOpts, and the new options for functions Send and SendBytes.

omani commented 7 years ago

any news about this after more than a year?

pebbe commented 7 years ago

RADIO and DISH are still in draft. If you want to use them in zmq4 you need to checkout the branch devel.

pebbe commented 7 years ago

The branch was called draft4.2, not devel. I removed this branch.

You can now use zmq4 including the draft things like this:

import (
    zmq "github.com/pebbe/zmq4/draft"
)
omani commented 7 years ago

I get the following error when switching to .../draft:

# command-line-arguments
/usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/tmp/go-link-906949768/000002.o:(.data+0x0): multiple definition of `zmq4_patch'
/tmp/go-link-906949768/000001.o:(.data+0x0): first defined here
/tmp/go-link-906949768/000002.o: In function `_cgo_5557a0482b07_Cfunc__Cmalloc':
/tmp/go-build/github.com/pebbe/zmq4/_obj/_cgo_export.c:16: multiple definition of `zmq4_minor'
/tmp/go-link-906949768/000001.o:/tmp/go-build/github.com/pebbe/zmq4/draft/_obj/_cgo_export.c:16: first defined here
/tmp/go-link-906949768/000002.o: In function `zmq4_get_event40':
/home/hasan/gocode/src/github.com/pebbe/zmq4/zmq4.go:50: multiple definition of `zmq4_get_event40'
/tmp/go-link-906949768/000001.o:/home/hasan/gocode/src/github.com/pebbe/zmq4/draft/zmq4.go:51: first defined here
/tmp/go-link-906949768/000002.o: In function `memcpy':
/usr/include/x86_64-linux-gnu/bits/string3.h:53: multiple definition of `zmq4_memcpy'
/tmp/go-link-906949768/000001.o:/usr/include/x86_64-linux-gnu/bits/string3.h:53: first defined here
/tmp/go-link-906949768/000002.o: In function `_cgo_5557a0482b07_Cfunc__Cmalloc':
/tmp/go-build/github.com/pebbe/zmq4/_obj/_cgo_export.c:16: multiple definition of `zmq4_major'
/tmp/go-link-906949768/000001.o:/tmp/go-build/github.com/pebbe/zmq4/draft/_obj/_cgo_export.c:16: first defined here
/tmp/go-link-906949768/000002.o: In function `zmq4_get_event41':
/home/hasan/gocode/src/github.com/pebbe/zmq4/zmq4.go:58: multiple definition of `zmq4_get_event41'
/tmp/go-link-906949768/000001.o:/home/hasan/gocode/src/github.com/pebbe/zmq4/draft/zmq4.go:59: first defined here
collect2: error: ld returned 1 exit status
pebbe commented 7 years ago

You need to import github.com/pebbe/zmq4 or github.com/pebbe/zmq4/draft, not both. And you can't import the latter when you're using a package that imports the former.

omani commented 7 years ago

ah yes. it worked. thank you.

omani commented 7 years ago

I see that a dish binds and a radio socket connects in https://github.com/pebbe/zmq4/blob/90d69e412a09549f2e90bac70fbb449081f1e5c1/draft/zmq42draft_test.go.

is this the way radio/dish is meant to be? I thought radio/dish behaves like a PUB/SUB pattern with some differences here and there. and a pub socket binds, a sub connects.

omani commented 7 years ago

In fact, I can't bind on a dish socket in my code. so I guess the test is wrong or maybe I misunderstood something.

pebbe commented 7 years ago

The test in zmq4 is based on this test: https://github.com/zeromq/libzmq/blob/master/tests/test_udp.cpp

omani commented 7 years ago

I found the reason for this: http://api.zeromq.org/4-2:zmq-udp

"With udp we can only connect the ZMQ_RADIO socket type."

since I am using tcp, it is the other way round. radio binds, dish connects.

everything is fine and working. thank you. I hope this draft will be merged in master soon.

sbhushan87 commented 6 years ago

Hi, I couldn't see draft4.2 branch, is it already merged to master ? thanks.

pebbe commented 6 years ago

instead of this:

import (
    zmq "github.com/pebbe/zmq4"
)

use this:

import (
    zmq "github.com/pebbe/zmq4/draft"
)
sbhushan87 commented 6 years ago

thanks @pebbe , Does this draft version compatible with latest libzmq (version 4.2) OR i need to install draft version of libzmq aswell ?

omani commented 6 years ago

@sbhushan87 I didn't have to install the draft version. radio/dish was already included in libzmq back then. it is only treated as a draft in pebbe's zmq4. someone correct me if I am wrong.

sujunbo commented 4 years ago

Hello,Do you need to compile libzmq using vs to use zeromq with go on Windows?