Class RouterToReqExample

java.lang.Object
org.sim0mq.demo.RouterToReqExample

public final class RouterToReqExample
extends Object
Example from http://stackoverflow.com/questions/20944140/zeromq-route-req-java-example-does-not-work. Added testing of send messages for correctly sent messages, plus a monitor that checks whether one of the conversations hangs. The lazy pirate pattern from the 0mq guide has been added to deal with possible timeouts.

BSD-style license. See OpenTrafficSim License.

$LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $, initial version Apr 20, 2017
Author:
Alexander Verbraeck
  • Field Details

  • Method Details

    • main

      public static void main​(String[] args) throws Exception
      While this example runs in a single process, that is just to make it easier to start and stop the example. Each thread has its own context and conceptually acts as a separate process.
      Parameters:
      args - args, can be empty
      Throws:
      Exception - on error
    • recvStringWithTimeout

      static String recvStringWithTimeout​(ZContext context, ZMQ.Socket socket, long timeoutMs, String resend)
      Parameters:
      context - the context
      socket - the socket
      timeoutMs - timeout in milliseconds
      resend - string to resend if it fails
      Returns:
      the read string after potential resending of the request or even reconnecting