Package org.sim0mq.demo
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 Summary
Fields Modifier and Type Field Description (package private) static AtomicInteger
completed
completed.(package private) static Random
rand
random stream.(package private) static AtomicInteger
staticBrokerIdRecv
static counter for broker identity.(package private) static AtomicInteger
staticBrokerMsgRecv
static counter for broker Message.(package private) static AtomicInteger
staticWorkerRecv
static counter for worker. -
Method Summary
Modifier and Type Method Description static void
main(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 String
recvStringWithTimeout(ZContext context, ZMQ.Socket socket, long timeoutMs, String resend)
-
Field Details
-
rand
random stream. -
staticWorkerRecv
static counter for worker. -
staticBrokerIdRecv
static counter for broker identity. -
staticBrokerMsgRecv
static counter for broker Message. -
completed
completed.
-
-
Method Details
-
main
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
-