# -*- coding: utf-8 -*- """ @contact: [email protected] @time: 2018/4/7 下午11:11 """ import sys from rbtmq.rabbitmq_client import channel channel.exchange_declare(exchange='direct_logs', exchange_type='direct') result = channel.queue_declare(exclusive=True) queue_name = result.method.queue # severities = sys.argv[1:] severities = ['black', 'white', 'yellow'] if not severities: sys.stderr.write("Usage: %s [info] [warning] [error]\n" % sys.argv[0]) sys.exit(1) for severity in severities: channel.queue_bind(exchange='direct_logs', queue=queue_name, routing_key=severity) print(' [*] Waiting for logs. To exit press CTRL+C') def callback(ch, method, properties, body): print(" [x] %r:%r" % (method.routing_key, body))
# -*- coding: utf-8 -*- """ @contact: [email protected] @time: 2018/4/7 下午10:10 """ import sys from rbtmq.rabbitmq_client import channel channel.exchange_declare(exchange='logs', exchange_type='fanout') message = ' '.join(sys.argv[1:]) or "info: Hello World!" channel.basic_publish(exchange='logs', routing_key='', body=message) print(" [x] Sent %r" % message)
# -*- coding: utf-8 -*- """ @contact: [email protected] @time: 2018/4/7 下午11:21 """ import sys from rbtmq.rabbitmq_client import channel channel.exchange_declare(exchange='topic_logs', exchange_type='topic') routing_key = sys.argv[1] if len(sys.argv) > 2 else 'anonymous.info' message = ' '.join(sys.argv[2:]) or 'Hello World!' channel.basic_publish(exchange='topic_logs', routing_key=routing_key, body=message) print(" [x] Sent %r:%r" % (routing_key, message))