Skip to content

Instantly share code, notes, and snippets.

@ssanderson
Created June 7, 2012 20:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssanderson/2891264 to your computer and use it in GitHub Desktop.
Save ssanderson/2891264 to your computer and use it in GitHub Desktop.
zmq node chain test
#Midpoint for zmq node chain test. Receives a message
#via SUB socket, then propagates that message out via
#PUB socket to sink nodes.
import zmq
context = zmq.Context()
receiver = context.socket(zmq.SUB)
receiver.connect("tcp://localhost:5555")
receiver.setsockopt(zmq.SUBSCRIBE, '')
propagator = context.socket(zmq.PUB)
propagator.bind("tcp://*:5556")
messagecount = 0
while messagecount < 5:
print "getting next message..."
msg = receiver.recv()
print "Received message: ", msg
print "Propagating message forward:", msg
propagator.send(msg)
messagecount +=1
#Endpoint for zmq node chain test.
import zmq
context = zmq.Context()
sinks = []
for i in range(5):
sinks.append(context.socket(zmq.SUB))
sinks[i].connect("tcp://localhost:5556")
sinks[i].setsockopt(zmq.SUBSCRIBE, '')
messagecount = 0
while messagecount < 5:
for i in range(5):
sinks[i].recv()
messagecount +=1
#Source node for zmq node chain test.
import zmq
context = zmq.Context()
source = context.socket(zmq.PUB)
source.bind("tcp://*:5555")
for message in range(0,5):
print "Sending message", message
source.send(str(message))
while True:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment