Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ZeroMQ: multiple remote (LAN) publishers

Tags:

python

zeromq

I have a basic ZeroMQ scenario consisting of two publishers and a subscriber. This has been working fine on a local computer until I decided to separate all process in different computers within my LAN. This is how I'm creating the ZeroMQ sockets (simplified Python code):

(Subscriber process running on machine with IP 192.168.1.52)

Publisher code (common for both publishers):

context = zmq.Context()
self.pub_socket = context.socket(zmq.PUB)
self.pub_socket.connect("tcp://192.168.1.52:5556")

Subscriber code:

context = zmq.Context()
self.sub_socket = context.socket(zmq.SUB)
self.sub_socket.bind("tcp://192.168.1.52:5556")
self.sub_socket.setsockopt(zmq.SUBSCRIBE, "")

I've tried entering tcp://127.0.0.1:5556 as the binding address:port for the subscriber but that makes no difference.

like image 213
dberenguer Avatar asked Oct 07 '22 01:10

dberenguer


2 Answers

I would suspect your issue might be related to the openness of the ports between your machines. Some operating systems have their own software firewalls so you may need to check if you need to open them up.

First I would check that you can do one of the simple req/rep between two machines:

# machine 1
import zmq
context = zmq.Context()
socket = context.socket(zmq.REP)
socket.bind("tcp://*:5556")
req = socket.recv()
socket.send(req) 

# machine 2
import zmq
context = zmq.Context()
socket = context.socket(zmq.REQ)
socket.connect("tcp://192.168.1.52:5556")
socket.send("FOO")
print socket.recv()

If you are having a problem with that, then you might want to check those ports.

Secondly, you also might try binding to all interfaces with: socket.bind("tcp://*:5556")

And for your actual goal, if all you need is a mutli-sender / single receiver, you can probably just use the PUSH/PULL instead of PUB/SUB

# one receiver
import zmq
context = zmq.Context()
socket = context.socket(zmq.PULL)
socket.bind("tcp://*:5556")

while True:
    print socket.recv()

# many senders
import zmq
context = zmq.Context()
socket = context.socket(zmq.PUSH)
socket.connect("tcp://192.168.1.52:5556")
socket.send("FOO")
like image 189
jdi Avatar answered Oct 12 '22 11:10

jdi


Did you walkthrough the "Missing Message Problem Solver" in the ZMQ guild?

Note that when using PUB/SUB pattern, there is a slow-joiner syndrome that always lose some messages. The syndrome can be eliminated if we do connect in the SUB and do bind in the PUB; however, when having multiple publishers, the subscriber needs to connect to all of them.

like image 34
Peter Avatar answered Oct 12 '22 09:10

Peter