Created
August 10, 2012 11:23
-
-
Save alper/3313566 to your computer and use it in GitHub Desktop.
Simplified zeromq PUSH/PULL example
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
import sys | |
import time | |
import zmq | |
context = zmq.Context() | |
# Socket to receive messages on | |
receiver = context.socket(zmq.PULL) | |
receiver.bind("tcp://*:5558") | |
while True: | |
print receiver.recv() |
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
import zmq | |
import random | |
import time | |
context = zmq.Context() | |
# Socket with direct access to the sink: used to syncronize start of batch | |
sink = context.socket(zmq.PUSH) | |
sink.connect("tcp://localhost:5558") | |
# Initialize random number generator | |
random.seed() | |
while True: | |
workload = random.randint(1, 100) | |
sink.send(str(workload)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment