Custom Search

Sunday, July 26, 2015

ZeroMQ Publish Subscribe Pattern Example

ZeroMQ Publish Subscribe Pattern Example

1)
Install pyzmq
$ pip install pyzmq

2)
Publisher
==========
import zmq
context = zmq.Context()
publisher = context.socket(zmq.PUB)
publisher.bind('tcp://127.0.0.1:1234')
publisher.send_multipart(['a', 'b'])
publisher.send_multipart(['c', 'd'])

3)
Subscriber
==========
import zmq
context = zmq.Context()
subscriber = context.socket(zmq.SUB)
subscriber.setsockopt(zmq.SUBSCRIBE, '')
subscriber.connect('tcp://127.0.0.1:1234')
subscriber.recv_multipart()

1 comment:

  1. https://github.com/zeromq/pyzmq/issues/669

    ReplyDelete