Exemplo n.º 1
0
class Subscriber(object):
    
    def __init__(self, channel_id):
        self.channel_id = channel_id
        self.r = ZMQPubSub(callback=self.callback)
        self.r.connect()
    
    def callback(self, evtype, *args, **kwargs):
        if evtype == CALLBACK_TYPE_CONNECTED:
            print 'connected'
            self.r.subscribe(self.channel_id)
        elif evtype == CALLBACK_TYPE_SUBSCRIBED:
            print 'subscribed to channel_id %s' % args[0]
        elif evtype == CALLBACK_TYPE_MESSAGE:
            print 'received on channel_id %s message %s' % (args[0], args[1])
            self.r.unsubscribe()
        elif evtype == CALLBACK_TYPE_UNSUBSCRIBED:
            print 'unsubscribed'
            self.r.disconnect()
        elif evtype == CALLBACK_TYPE_DISCONNECTED:
            print 'disconnected'
            ioloop.stop()
Exemplo n.º 2
0
 def __init__(self, channel_id):
     self.channel_id = channel_id
     self.r = ZMQPubSub(callback=self.callback)
     self.r.connect()
Exemplo n.º 3
0
from async_pubsub.zmq_pubsub import ZMQPubSub

if __name__ == '__main__':
    ZMQPubSub.start_service()
Exemplo n.º 4
0
import sys
from async_pubsub.zmq_pubsub import ZMQPubSub

if __name__ == '__main__':
    channel_id = sys.argv[1]
    message = sys.argv[2]
    ZMQPubSub.publish(channel_id, message)