Created
June 7, 2012 20:08
-
-
Save ssanderson/2891264 to your computer and use it in GitHub Desktop.
zmq node chain test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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