示例#1
0
文件: bread.py 项目: zerok/circus
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)
示例#2
0
 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
示例#3
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