ZeroMQ Publish Subscribe Pattern Python 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)
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()
https://github.com/zeromq/pyzmq/issues/669
ReplyDelete