-1

I'm trying to get a basic implementation of a ZMQ publisher and subscriber working, but it's failing silently. I'm using JeroMQ 0.5.2 (the current version) and Java 8.

Consider the following official test file: https://github.com/zeromq/jeromq/blob/master/src/test/java/org/zeromq/PubSubTest.java

I've copied the first test (testRaceConditionIssue322) in its entirety into a new main class and run it. The publisher binds to the port, and claims to send every message, but the receiver does not receive a single message. Adding logs indicates that the subscriber believes itself to be subscribed before the publisher sends messages.

I've tried this on two computers, as well as with different code, and it's the same net result each time. What gives?

Erhannis
  • 4,256
  • 4
  • 34
  • 48

1 Answers1

0

Ok, I figured it out. Two things converged in an unfortunate way.

  1. The test I linked was, possibly on purpose, starting the subscriber before the publisher. For some reason, the subscriber reported a successful connection, even though the publisher had not yet opened the port. It did not make a connection, and did not receive the messages subsequently sent. When I made sure the publisher was bound and listening for connections, and then the subscriber connected, and then the publisher published messages, it worked how I as expecting.
  2. The OTHER code I was using, as a subscriber, had a line in it I didn't notice - socket.hasReceiveMore(). It was expecting two strings in one message, but I was sending two strings separately. This meant part of the receiver code never executed - it received the strings I was sending, but discarded them as partial messages. When I sent my first string with the flag publisher.send(msg, ZMQ.SNDMORE); (and the second without), it worked as I expected.
Erhannis
  • 4,256
  • 4
  • 34
  • 48