[zeromq-dev] ZMQ SUB and PUB questions

Bill Torpey wallstprog at gmail.com
Thu Dec 15 17:50:10 CET 2022

Hi Joris:

This is an ancient bug/feature in ZeroMQ, and some earlier discussions can be found [here](https://github.com/zeromq/libzmq/issues/2267).

There are a couple of things going on here that contribute to the problem:

- Connections in ZeroMQ are done asynchronously — when you call connect, that initiates the connection, but the connection is not actually made until some time later (as per Brett’s email).

- Subscription information is exchanged between sub and pub at connect time — if sub connects to pub, the subscription information is carried in the initial connection message.  However if pub connects to sub, then an additional message exchange is needed to send subscription information, and this takes addl. time.

One solution is to sleep after connect to allow all this behind-the-scenes stuff to happen. (You’ll see that in the unit tests, which are liberally sprinkled with “msleep(SETTLE_TIME)” calls).  Of course, this is not a reliable solution.

If you need to be certain that a particular message arrives (or not), you’re going to need an additional protocol layer on top of vanilla ZeroMQ.  There are several out there, but I think highly of this one (https://github.com/nyfix/OZ).  If you’re OK with using the MAMA API, OZ can significantly flatten the ZeroMQ learning curve.

Good luck!


> On Dec 15, 2022, at 9:40 AM, Joris OFFOUGA <offougajoris at gmail.com> wrote:
> Hi Brett,
> Thank you for your reply. I added sleep after SUB connection but it doesn't work but when I change from a tcp socket to ipc it works. Any difference between tcp or ipc socket?
> Best Regards,
> Joris
>> Le 15 déc. 2022 à 15:07, Brett Viren <brett.viren at gmail.com> a écrit :
>> On Thu, Dec 15, 2022 at 8:58 AM Brett Viren <brett.viren at gmail.com> wrote:
>>> This is imitated by our app code with bind()/connect()
>>> calls but ultimately completed behind the scene by libzmq.
>> I mean *initiated* no imitated!
>> -B.
>> _______________________________________________
>> zeromq-dev mailing list
>> zeromq-dev at lists.zeromq.org
>> https://lists.zeromq.org/mailman/listinfo/zeromq-dev
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> https://lists.zeromq.org/mailman/listinfo/zeromq-dev

More information about the zeromq-dev mailing list