[zeromq-dev] pub sub - first messages do not arrive from publisher to subscriber even though publisher is launched after the subscriber

Omer Bacharach omer at toot-trading.com
Mon Sep 19 13:52:44 CEST 2011


Hi all,

I'm trying to implement the pub sub design pattern using zeromq framework.
The idea is to launch a subscriber and afterwards to launch the publisher.
The subscriber will listen to 100 messages and the publisher will publish
100 messages.
So far so good...
However what actually happens is that even that the subscriber is already up
and running when the publisher is launched , not all of the messages are
received by the subscriber (a 100 messages will be picked up by the
subscriber if the publisher will send at least 500 message). It seems that
the first messages sent by the publisher do not arrive to the subscriber.

Any ideas?

Thanks in advance,
Omer.


***Subscriber code (launched before the publisher)***

    int i=0;
    zmq::context_t context (1);
    zmq::socket_t subscriber (context, ZMQ_SUB);
    subscriber.connect("tcp://localhost:5556");
    subscriber.setsockopt(ZMQ_SUBSCRIBE, "", 0);

    for (int update_nbr = 0; update_nbr < 100; update_nbr++)
    {
        zmq::message_t update;
        subscriber.recv(&update);
        i++;
        std::cout<<"receiving  :"<<i<<std::endl;
    }

***Publisher code (launched after the subscriber)***

    zmq::context_t context (1);
    zmq::socket_t publisher (context, ZMQ_PUB);
    publisher.bind("tcp://*:5556");

    int i = 0;
    for (int update_nbr = 0; update_nbr < 100; update_nbr++)
    {
        //  Send message to all subscribers
        zmq::message_t request (20);

        time_t seconds;
        seconds = time (NULL);

        char update [20]="";
        sprintf (update, "%ld", seconds);

        memcpy ((void *) request.data (), update,strlen(update));
        publisher.send(request);
        i++;
        std::cout << "sending :" << i << std::endl;
}




-- 
Omer Bacharach
Director of Software Development
Toot Trading Ltd.
omer at toot-trading.com
Mobile +972-544-317959
Office +972-3-7449466
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20110919/26d35478/attachment.htm>


More information about the zeromq-dev mailing list