def api(): """WebSocket endpoint; Takes a 'topic' GET param.""" ws = request.environ.get('wsgi.websocket') topic = request.args.get('topic') if None in (ws, topic): return topic = topic.encode('ascii') for message, message_topic in CircusConsumer(topic, endpoint=ZMQ_ENDPOINT): response = json.dumps(dict(message=message, topic=message_topic)) ws.send(response)
def __init__(self, endpoint=DEFAULT_ENDPOINT_STATS, ssh_server=None, context=None): CircusConsumer.__init__(self, ['stat.'], context, endpoint, ssh_server)
def __init__(self, endpoint='tcp://127.0.0.1:5557', context=None): CircusConsumer.__init__(self, ['stat.'], context, endpoint)
def handle_sub(self, cmd, opts, topics, endpoint, timeout, ssh_server, ssh_keyfile): consumer = CircusConsumer(topics, endpoint=endpoint) for topic, msg in consumer: print("%s: %s" % (topic, msg)) return 0
from circus.consumer import CircusConsumer import json ZMQ_ENDPOINT = 'tcp://127.0.0.1:5556' topic = 'show:' for message, message_topic in CircusConsumer(topic, endpoint=ZMQ_ENDPOINT): response = json.dumps(dict(message=message, topic=message_topic)) print response