[zeromq-dev] Router/Dealer lost messages (libzmq 3.1.1)

john skaller skaller at users.sourceforge.net
Tue Jan 24 02:04:14 CET 2012


On 24/01/2012, at 9:08 AM, Michael Compton wrote:

> Hi,
> 
> I am trying to do explicit message routing using Router/Dealer
> connection pattern, as documented in the zguide:
> http://zguide.zeromq.org/page:all#toc49 
> 
> But the messages never arrive at the destination.
> 
> Please find the code here:
> http://paste.lisp.org/display/127256#1
> Program output here:
> http://paste.lisp.org/display/127256#2



This is a synchronisation problem.

This Felix code works fine:

///////////
open ZMQ;

  println ("Starting..."); fflush (stdout);
  var context = zmq_init (1);
  
  var dealer = zmq_socket (context, ZMQ_DEALER); 
  dealer . set_opt$ zmq_identity "A";
  dealer.connect "tcp://localhost:5555";

  var router = zmq_socket (context, ZMQ_ROUTER); 
  router.bind "tcp://*:5555";

  Faio::sleep(sys_clock,1.0);
  
  println ("Sending Payload"); fflush (stdout);
  dealer.send_string "PAYLOAD";

  println ("Waiting for payload"); fflush (stdout);
  var s1 = recv_string router;
  var s2 = recv_string router;

  println ("Payload recved '"+s1+"': '"+s2+"'"); fflush (stdout);

// send back to router

  router.send_string_part s1;
  router.send_string s2;

// fetch from dealer
  var s3 = recv_string dealer;
  println ("Payload returned '"+s3); fflush (stdout);

  close (dealer);
  close (router);
  term (context);
////
Starting...
Sending Payload
Waiting for payload
Payload recved 'A': 'PAYLOAD'
Payload returned 'PAYLOAD
////

The second part of this code is the same as yours. But if you remove
the first step it hangs:

/////
open ZMQ;

  println ("Starting..."); fflush (stdout);
  var context = zmq_init (1);
  
  var dealer = zmq_socket (context, ZMQ_DEALER); 
  dealer . set_opt$ zmq_identity "A";
  dealer.connect "tcp://localhost:5555";

  var router = zmq_socket (context, ZMQ_ROUTER); 
  router.bind "tcp://*:5555";

  Faio::sleep(sys_clock,1.0);
  
/*
  println ("Sending Payload"); fflush (stdout);
  dealer.send_string "PAYLOAD";

  println ("Waiting for payload"); fflush (stdout);
  var s1 = recv_string router;
  var s2 = recv_string router;

  println ("Payload recved '"+s1+"': '"+s2+"'"); fflush (stdout);

// send back to router
*/
var s1 = "A";
var s2 = "PAYLOAD";

  router.send_string_part s1;
  router.send_string s2;

// fetch from dealer
  var s3 = recv_string dealer;
  println ("Payload returned '"+s3); fflush (stdout);

  close (dealer);
  close (router);
  term (context);

////

Looks like you have to send something to the router first to wake it up :)
Or maybe the dealer is asleep until you kick it ..

--
john skaller
skaller at users.sourceforge.net







More information about the zeromq-dev mailing list