简体   繁体   English

ZeroMQ 发布消息失败

[英]ZeroMQ failing to publish messages

I'm trying to get a basic implementation of a ZMQ publisher and subscriber working, but it's failing silently.我正在尝试使 ZMQ 发布者和订阅者的基本实现正常工作,但它无声无息地失败了。 I'm using JeroMQ 0.5.2 (the current version) and Java 8.我正在使用 JeroMQ 0.5.2(当前版本)和 Java 8。

Consider the following official test file: https://github.com/zeromq/jeromq/blob/master/src/test/java/org/zeromq/PubSubTest.java考虑以下官方测试文件: 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.我已将第一个测试 (testRaceConditionIssue322) 全部复制到一个新的主类中并运行它。 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?是什么赋予了?

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() .我作为订阅者使用的 OTHER 代码中有一行我没有注意到 - 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);当我发送带有标志的第一个字符串publisher.send(msg, ZMQ.SNDMORE); (and the second without), it worked as I expected. (第二个没有),它按我的预期工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM