rabbitmq-tutorials/python/emit_log_direct.py
Xiangzhuang Shen cc2110ef4c fix:python pep8
2023-09-22 15:40:12 +08:00

18 lines
494 B
Python
Executable File

#!/usr/bin/env python
import sys
import pika
connection = pika.BlockingConnection(
pika.ConnectionParameters(host='localhost'))
channel = connection.channel()
channel.exchange_declare(exchange='direct_logs', exchange_type='direct')
severity = sys.argv[1] if len(sys.argv) > 2 else 'info'
message = ' '.join(sys.argv[2:]) or 'Hello World!'
channel.basic_publish(
exchange='direct_logs', routing_key=severity, body=message)
print(f" [x] Sent {severity}:{message}")
connection.close()