Skip to content

Instantly share code, notes, and snippets.

@jkarneges
Created December 8, 2015 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkarneges/d3179119cdb412da9daa to your computer and use it in GitHub Desktop.
Save jkarneges/d3179119cdb412da9daa to your computer and use it in GitHub Desktop.
listen for pushpin subscription changes
import sys
import zmq
if len(sys.argv) < 2:
print 'usage: %s [pub_spec]' % sys.argv[0]
sys.exit(1)
spec = sys.argv[1]
zmq_context = zmq.Context.instance()
sock = zmq_context.socket(zmq.XPUB)
sock.rcvhwm = 0 # ensure the subscription list is never truncated
sock.immediate = 1 # clear subscriptions on disconnect
sock.connect(spec)
while True:
m = sock.recv()
mtype = m[0]
topic = m[1:]
if mtype == '\x01':
print 'SUB %s' % topic
elif mtype == '\x00':
print 'UNSUB %s' % topic
@jkarneges
Copy link
Author

run like this:

python subs.py tcp://localhost:5562

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment