Created
April 17, 2011 23:45
-
-
Save bmjames/924612 to your computer and use it in GitHub Desktop.
Async ZeroMQ example using gevent_zeromq
This file contains hidden or 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 gevent | |
from gevent_zeromq import zmq | |
context = zmq.Context() | |
def sub(): | |
subscriber = context.socket(zmq.SUB) | |
subscriber.connect('tcp://localhost:5561') | |
subscriber.setsockopt(zmq.SUBSCRIBE, '') | |
while True: | |
msg = subscriber.recv() | |
print "Subscriber received:", msg | |
def pub(): | |
publisher = context.socket(zmq.PUB) | |
publisher.bind('tcp://*:5561') | |
for msg in (str(i) for i in xrange(5)): | |
print "Publishing message:", msg | |
publisher.send(msg) | |
gevent.sleep(1) | |
gevent.spawn(sub) | |
gevent.spawn(pub) | |
gevent.sleep(5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment