Created
August 14, 2013 21:11
-
-
Save helielson/6235676 to your computer and use it in GitHub Desktop.
Pub/Sub example with ZeroMQ
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 time | |
import zmq | |
context = zmq.Context() | |
socket = context.socket(zmq.PUB) | |
socket.bind("tcp://127.0.0.1:6000") | |
while True: | |
socket.send("Msg") | |
time.sleep(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
import zmq | |
from zmq.eventloop.zmqstream import ZMQStream | |
from zmq.eventloop import ioloop | |
ioloop.install() | |
zmq_context = zmq.Context() | |
subscribe_socket = zmq_context.socket(zmq.SUB) | |
subscribe_socket.setsockopt(zmq.SUBSCRIBE, '') | |
subscribe_socket.connect('tcp://127.0.0.1:6000') | |
def echo(msg): | |
print msg | |
sub_stream = ZMQStream(subscribe_socket) | |
sub_stream.on_recv(echo) | |
app_ioloop = ioloop.IOLoop.instance() | |
app_ioloop.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment