9

I'm using ZeroMQ to facilitate a publish/subscribe environment I'm needing. I'm running a publish server on machine A using Python (using EventLoop), and right now I have one subscriber running in C++ on machine B and a second subscriber running in Python (using EventLoop) on machine C.

If machine B subscribes to machine A before machine C does, then B gets subscribed messages and C does not. Furthermore, if I look at the established connections on machine A, there only exists a connection for machine B but not for C. If machine C subscribes to A before B does, then it's the other way around.

Here's my publisher code:

import zmq
from zmq.eventloop import ioloop, zmqstream

ioloop.install()

context   = zmq.Context(1)
socket    = context.socket(zmq.PUB)
publisher = zmqstream.ZMQStream(socket)
socket.bind("tcp://*:1337")

def publish():
  publisher.send_multipart(("heartbeat", "OHAI"))

ioloop.PeriodicCallback(publish, 5000).start()
ioloop.IOLoop.instance().start()

Here's my Python subscriber code:

import zmq
from zmq.eventloop import ioloop, zmqstream

ioloop.install()

context    = zmq.Context(1)
socket     = context.socket(zmq.SUB)
subscriber = zmqstream.ZMQStream(socket)
socket.setsockopt(zmq.SUBSCRIBE, "heartbeat")
socket.connect("tcp://pub.local:1337")

def subscription(message):
  print "Message Received: %s" % (message[1])

subscriber.on_recv(subscription)
ioloop.IOLoop.instance().start()

Why isn't my publisher accepting multiple incoming subscriber sockets? It's probably worth noting that multiple subscribers works fine when running them on machine A, but I don't think it's a firewall issue because I tested subscriber connections from B and C to A with the firewall disabled.

Bryan
  • 2,205
  • 1
  • 23
  • 43
  • any chance you could publish either (or both) of your subscriber codes? – g19fanatic Oct 23 '12 at 11:59
  • @g19fanatic - sure, I've edited my original question to include the code for my Python subscriber. I don't have access to the C++ subscriber right now, but I've confirmed that I get the same result if the Python subscriber is running on both machines B and C (meaning, the fact that one of the subscribers is written in C++ doesn't seem to be relevant so I probably shouldn't have complicated the question by making that distinction). – Bryan Oct 23 '12 at 15:20
  • Very strange. Can you test the code with publisher on B and then on C, with subscribers on other nodes? Looks like there is a network issue. – mechmind Oct 23 '12 at 16:04
  • @mechmind - good idea. I'm currently testing over my corporate network, which has lots of routes and hops between all the machines. I'll setup a quick VM environment using Vagrant and post the results ASAP. – Bryan Oct 23 '12 at 16:10
  • I'm unfamiliar with the whole ioloop setup you have going (can see how it works and everything, just do not have experience running exec loops that way)... have you tried doing a very simple pub/sub test as given in the zmq guide examples? Having a simple working example could help eliminate most of the issues if they are present... – g19fanatic Oct 23 '12 at 16:59
  • such as https://gist.github.com/3940128 – g19fanatic Oct 23 '12 at 17:10
  • @Bryan Hi, have you tested pub-sub on different hosts? – mechmind Oct 24 '12 at 15:25

1 Answers1

5

Thanks to everyone for all the helpful comments in the original posting. This behavior turned out to be due to a mismatch in ZeroMQ versions being used... an oversight on my part.

Bryan
  • 2,205
  • 1
  • 23
  • 43