Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

High-water mark w.r.t message parts #171

Open
versemonger opened this issue Dec 4, 2020 · 0 comments
Open

High-water mark w.r.t message parts #171

versemonger opened this issue Dec 4, 2020 · 0 comments

Comments

@versemonger
Copy link

versemonger commented Dec 4, 2020

Hello,
I read of

Lastly, the high-water marks are counted in message parts, not whole messages. If you are sending two-part messages, the default HWM is 500. When you use the ROUTER socket type (discussed in detail in the next chapter), every message is at least two parts.

in section High-Water Marks, Chapter 2, ZeroMQ by Pieter Hintjens, O'Reilly Media, Inc., 2013
But when I tested sending mutli-part messages, I found that a multi-part message is actually treated as a single message by high-water mark.
e.g., the following code with jzmq

   package org.zeromq;

import java.util.Collection;

/**
 * Simple App to display version information about jzmq.
 * 
 */
public class App {

    public static void main(final String[] args) throws Exception {

        final Package p = App.class.getPackage();
        final String appname = p.getSpecificationTitle();
        final String versionMaven = p.getSpecificationVersion();
        String[] version = new String[] { "", "" };
        if (p.getImplementationVersion() != null) {
            version = p.getImplementationVersion().split(" ", 2);
        }

        String zmqVersion = null;

        try {

            final int major = ZMQ.version_major();
            final int minor = ZMQ.version_minor();
            final int patch = ZMQ.version_patch();
            zmqVersion = major + "." + minor + "." + patch;

        } catch (Throwable x) {
            zmqVersion = "ERROR! " + x.getMessage();
        }

        final String fmt = "%-7.7s %-15.15s %s%n";

        System.out.printf(fmt, "ZeroMQ", "version:", zmqVersion);
        System.out.printf(fmt, appname, "version:", versionMaven);
        System.out.printf(fmt, appname, "build time:", version[1]);
        System.out.printf(fmt, appname, "build commit:", version[0]);

        System.out.println();
        System.out.println("JNI lib location:       "
                + (EmbeddedLibraryTools.LOADED_EMBEDDED_LIBRARY ? "embedded" : "java.library.path"));
        System.out.println("current platform:       " + EmbeddedLibraryTools.getCurrentPlatformIdentifier());
        final Collection<String> files = EmbeddedLibraryTools.getEmbeddedLibraryList();
        for (final String file : files) {
            System.out.println("embedded library:       " + file);
        }

        ZMQ.Context context = ZMQ.context(1);

        // Socket to talk to server
        System.out.println("Connecting to hello world server");

        ZMQ.Socket socket = context.socket(ZMQ.DEALER);
        socket.setSndHWM(4L);
        socket.connect("inproc://ventilator");
        for(int requestNbr = 0; requestNbr != 10; requestNbr++) {
            String request = "Hello";
            System.out.println("Sending Hello " + requestNbr );
            socket.send(request, ZMQ.SNDMORE);
            socket.send(request, ZMQ.SNDMORE);
            socket.send(request, ZMQ.SNDMORE);
            socket.send(request, ZMQ.SNDMORE);
            socket.send(request);
            Thread.sleep(1000);

        }

        socket.close();
        context.term();
    }

}

output

^C[zhul@115306277ae5 jzmq]$ java -classpath target/classes org.zeromq.App
ZeroMQ  version:        4.0.4
null    version:        null
null    build time:     
null    build commit:   

JNI lib location:       java.library.path
current platform:       amd64/Linux
Connecting to hello world server
Sending Hello 0
Sending Hello 1
Sending Hello 2
Sending Hello 3
Sending Hello 4

(and it blocked at Sending Hello 4)
If hwk treats a multi-part message as multiple messages, then it should have blocked at the first message.

So does it mean that zeromq has changed since the book was published?

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant