I have following “hello world” jeromq PUSH-PULL client and server. Only after I set High Water Mark values am I able to transmit without dropping messages.
import org.jeromq.ZMQ;
public class TestTcpServer {
public static void main(String[] args) {
ZMQ.Context context = ZMQ.context(1);
ZMQ.Socket socket = context.socket(ZMQ.PULL);
System.out.println("Binding TCP server on port 5555");
//socket.setRcvHWM(100_000);
socket.bind("tcp://*:5555");
int x;
x = 0;
while (true) {
x++;
byte[] raw = socket.recv(0);
String rawMessage = new String(raw);
if (x > 99_997) {
System.out.println(x);
System.out.println(rawMessage);
}
}
}
}
//client
import java.io.IOException;
import org.jeromq.ZMQ;
public class TestTcpClient {
/**
* @param args
* @throws InterruptedException
* @throws IOException
*/
public static void main(String[] args) throws InterruptedException,
IOException {
ZMQ.Context context = ZMQ.context(1);
ZMQ.Socket socket = context.socket(ZMQ.PUSH);
socket.connect("tcp://localhost:5555");
//socket.setRcvHWM(100_000);
System.out.println("Sending 100 000 transactions over TCP..."); long start = System.currentTimeMillis();
for (int request_nbr = 0; request_nbr != 100_000; request_nbr++) {
String requestString = "message";
byte[] request = requestString.getBytes();
boolean success = socket.send(request, 0);
if (!success) {
System.out.println("sending message failed!");
}
}
long end = System.currentTimeMillis();
System.out.print("Time: ");
System.out.print(end - start);
System.out.println(" ms");
socket.close();
context.term();
}
}
According to 0Mq documentation, only PUB sockets will drop messages when high water mark is reached. Since I am using PUSH-PULL sockets, why are messages being dropped?
It seems to me that HWM is a dynamic property of the system, so while I have been able to resolve dropping messages in this hello world example, I wonder if I can count on jeromq not to drop messages in a real world situation?