Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ZeroMQ Non-Blocking Non-Queueing Push

Tags:

c#

zeromq

I am using the C# wrapper for ZeroMQ but this seems more like an underlying issue with ZeroMQ.

Is there any way to push a message without blocking and without queueing? If the server is not up I would like the messages to be permanently disposed without blocking.

Here are the settings I've tried so far:

1)

Send (Blocking send)

High water mark = 0

This (stragely) does not block, but it seems to queue in memory until the socket is connected (memory keeps rising for the process).

2)

Send (Non-Blocking send)

High water mark = 1

This is a race condition. If I send two messages in rapid succession one message is sometimes thrown out for exceeding the high water mark.

3)

Poll the socket to figure out if it's going to block. This doesn't really help because I still have to put one (old) message in the queue before it starts blocking (if I set HWM = 1).

Non-blocking send with any high water mark is undesirable because as soon as the server comes back online it gets a bunch of old messages from clients.

Blocking send doesn't work because I don't want to block.

like image 904
adotout Avatar asked Dec 05 '25 04:12

adotout


1 Answers

What you seem to be looking for is simply a PUB socket. This socket type never blocks on send, and discards any message it cannot send to a subscriber. See this page : http://api.zeromq.org/3-2:zmq-socket .

On a side note, you do not need to use this socket for "real" pub/sub, you can use it for nonblocking communication between two nodes by having only one PUB and one SUB socket by endpoint. Your server will not get "old" messages after a reconnect because the PUB sockets will have dropped the messages it could not send while the server was disconnected. Nevertheless i believe that while you cannot avoid some internal ZMQ "queuing", it should have little bearing on your use case.
like image 156
JJ15k Avatar answered Dec 07 '25 16:12

JJ15k



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!