2

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?

Dan
  • 11,077
  • 20
  • 84
  • 119

2 Answers2

0

Thank you for reporting.

Yes, PUSH/PULL must not drop messages.

There was a bug on the latest leap for ZMTP 2.0 support.

Please try with the latest snapshot.

Also I would recommend you add socket.setLinger(some_milli_seconds) on the client side when you want to quit the application after sending a message.

jenzz
  • 7,239
  • 6
  • 49
  • 69
Min Yu
  • 194
  • 1
  • 5
  • I experimented with linger settings to no effect, will try the latest snapshot. – Dan Nov 13 '12 at 18:31
0

It should work OK in JeroMQ 0.3, I made a simple benchmark here http://nguyentantrieu.info/blog/benchmark-pubsub-jeromq-java/