[zeromq-dev] pub-sub losing messages

Pieter Hintjens ph at imatix.com
Tue May 21 19:02:14 CEST 2013


On pub-sub sockets, when you exceed the HWM, messages are dropped. (This is
the only sane strategy to avoid memory exhaustion when subscribers run too
slowly.)

You're sending 100K messages with a HWM of 1,000, so about 99% of the
messages are going to be dropped.

If the scenario of sending that many messages in one go is realistic, then
raise the HWM to suit.

-Pieter


On Tue, May 21, 2013 at 6:50 PM, Michael Keselman <
michael.keselman at gmail.com> wrote:

> I am playing ZMQ using Java. I created very basic pub/sub application (see
> below) with subscriber emulating slow response via random delay.
> Unfortunately something isn't working. Whether I run multiple subscribers
> or only one, they have never received all messages. I thought that setting
> high water mark would help, but it didn't. Am I doing something wrong or
> missing some nuance?
>
> -----Pub-----
>
> import org.zeromq.ZMQ;
>
> public class Pub {
>         public static void main(String[] args) {
>                 ZMQ.Context context = ZMQ.context(1);
>         ZMQ.Socket publisher = context.socket(ZMQ.PUB);
>         publisher.setHWM(1000);
>         publisher.bind("tcp://*:5555");
>
>         long counter = 0;
>                 String msg;
>                 for (int i=0; i<100000; i++){
>                 msg = Long.toString(counter)+"*******";
>                 publisher.send(msg , 0);
>                         System.out.println(msg);
>                         counter++;
>         }
>
>         publisher.close ();
>         context.term ();
>         }
>
> }
>
> -----Sub-----
>
> import org.zeromq.ZMQ;
> import java.util.Random;
>
> public class sub {
>         public static void main(String[] args) throws Exception{
>                 Random rand = new Random();
>                 ZMQ.Context context = ZMQ.context(1);
>         ZMQ.Socket subscriber = context.socket(ZMQ.SUB);
>         subscriber.connect("tcp://localhost:5555");
>                 subscriber.subscribe("".getBytes());
>
>                 String msg;
>         while (1>0){
>             msg = subscriber.recvStr(0);
>             System.out.println(msg);
>                         Thread.sleep(rand.nextInt(3));
>         }
>         //subscriber.close();
>         //context.term();
>         }
> }
>
>
>
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20130521/71aff3fa/attachment.htm>


More information about the zeromq-dev mailing list