Skip to content

Instantly share code, notes, and snippets.

@helielson
Created August 14, 2013 21:11
Show Gist options
  • Save helielson/6235676 to your computer and use it in GitHub Desktop.
Save helielson/6235676 to your computer and use it in GitHub Desktop.
Pub/Sub example with ZeroMQ
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)
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