Package org.sim0mq.test
Class RouterToReqExample
- java.lang.Object
-
- org.sim0mq.test.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 Summary
Fields Modifier and Type Field Description (package private) static AtomicIntegercompletedcompleted.(package private) static Randomrandrandom stream.(package private) static AtomicIntegerstaticBrokerIdRecvstatic counter for broker identity.(package private) static AtomicIntegerstaticBrokerMsgRecvstatic counter for broker Message.(package private) static AtomicIntegerstaticWorkerRecvstatic counter for worker.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidmain(String[] args)While this example runs in a single process, that is just to make it easier to start and stop the example.(package private) static StringrecvStringWithTimeout(ZContext context, ZMQ.Socket socket, long timeoutMs, String resend)
-
-
-
Field Detail
-
rand
static Random rand
random stream.
-
staticWorkerRecv
static AtomicInteger staticWorkerRecv
static counter for worker.
-
staticBrokerIdRecv
static AtomicInteger staticBrokerIdRecv
static counter for broker identity.
-
staticBrokerMsgRecv
static AtomicInteger staticBrokerMsgRecv
static counter for broker Message.
-
completed
static AtomicInteger completed
completed.
-
-
Method Detail
-
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 contextsocket- the sockettimeoutMs- timeout in millisecondsresend- string to resend if it fails- Returns:
- the read string after potential resending of the request or even reconnecting
-
-