[zeromq-dev] Router/Dealer lost messages

Pasi Mankinen mailing.list at manageapp.com
Fri Feb 17 03:50:42 CET 2012


For 3.1.x release:

More tests and ifo about  ZMQ_ROUTER to ZMQ_ROUTER bug LIBZMQ-304.
https://zeromq.jira.com/browse/LIBZMQ-304

ZMQ_ROUTER to ZMQ_ROUTER does not work for first sent messages. Message parts are ok. In this test s_dump() is a non-blocking read. Blocking read will block in first s_dump() call forever.

CODE:
  long err;	
  void *context = zmq_init (1);
  void *server = zmq_socket (context, ZMQ_ROUTER);
  err = zmq_setsockopt (server, ZMQ_IDENTITY, "SERVER", 6);
  err = zmq_bind (server, "tcp://127.0.0.1:5555");

  void *worker = zmq_socket (context, ZMQ_ROUTER);
  err = zmq_setsockopt (worker, ZMQ_IDENTITY, "WORKER", 6);
  err = zmq_connect (worker, "tcp://127.0.0.1:5555");
    
  sleep_seconds (0.5); // sleep in seconds
  
  s_sendmore (worker, (char *)"SERVER");
  s_sendmore (worker, (char *)"");
  s_send     (worker, (char *)"send to server1");
  sleep_seconds (0.001); // sleep in seconds
  s_dump     (server);   // print to console
  
  s_sendmore (worker, (char *)"SERVER");
  s_sendmore (worker, (char *)"");
  s_send     (worker, (char *)"send to server2");
  sleep_seconds (0.001); // sleep in seconds
  s_dump     (server);   // print to console
  
  s_sendmore (server, (char *)"WORKER");
  s_sendmore (server, (char *)"");
  s_send     (server, (char *)"send to worker1");
  sleep_seconds (0.001); // sleep in seconds
  s_dump     (worker);   // print to console
  
  s_sendmore (worker, (char *)"SERVER");
  s_sendmore (worker, (char *)"");
  s_send     (worker, (char *)"send to server3");
  sleep_seconds (0.001); // sleep in seconds
  s_dump     (server);   // print to console
  
  s_sendmore (server, (char *)"WORKER");
  s_sendmore (server, (char *)"");
  s_send     (server, (char *)"send to worker2");
  sleep_seconds (0.001); // sleep in seconds
  s_dump     (worker);   // print to console
  
  zmq_close(worker); 
  zmq_close(server); 
  zmq_term (context);

OUTPUT:
----------------------------------------
[006] SERVER
[000] 
[015] send to worker1
----------------------------------------
[006] WORKER
[000] 
[015] send to server3
----------------------------------------
[006] SERVER
[000] 
[015] send to worker2



ROUTER to DEALER works, but I'm not sure sould we get those kind of message parts?

CODE:
...
    void *worker = zmq_socket (context, ZMQ_DEALER);
    err = zmq_setsockopt (worker, ZMQ_IDENTITY, "WORKER", 6);
    err = zmq_connect (worker, "tcp://127.0.0.1:5555");
    
    sleep_seconds (0.5); // sleep in seconds
    
    s_send     (worker, (char *)"send to server1");
    sleep_seconds (0.001); // sleep in seconds
    s_dump     (server);   // print to console
    
    s_sendmore (server, (char *)"WORKER");
    s_sendmore (server, (char *)"");
    s_send     (server, (char *)"send to worker1");
    sleep_seconds (0.001); // sleep in seconds
    s_dump     (worker);   // print to console
...

OUTPUT:
----------------------------------------
[006] WORKER
[015] send to server1
----------------------------------------
[000] 
[015] send to worker1


--
Regards,

Pasi Mankinen
Finland


More information about the zeromq-dev mailing list