import gnsq conn = gnsq.Nsqd('localhost', 4150) conn.publish('test', 'hello world!') messages = ['{} bottles of beer on the wall'.format(count) for count in xrange(99, 0, -1)] conn.multipublish('beers', messages) # Read our messages import gevent reader = gnsq.Reader('beers', 'singer', nsqd_tcp_addresses=['localhost:4150']) @reader.on_message.connect def sing(reader, message): print message.body + '!' print message.body + ',' print message.body + '.' print 'Take one down, pass it around...' if message.body.startswith('1 '): print '0 bottles of beer on the wall!!!!!' gevent.spawn(reader.close) reader.start()