commitLaba4

This commit is contained in:
2510m
2023-12-18 16:41:19 +04:00
parent eb966f9a4e
commit 36815227e1
30 changed files with 503 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
import pika
import sys
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
channel = connection.channel()
channel.exchange_declare(exchange='LyamzinaLogs', exchange_type='fanout')
message = ' '.join(sys.argv[1:]) or "Info: Hello, I am Lyamzina Maria!"
channel.basic_publish(exchange='LyamzinaLogs', routing_key='', body=message)
print(f" [x] Отправлено сообщение: {message}")
connection.close()

View File

@@ -0,0 +1,21 @@
import pika
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
channel = connection.channel()
channel.exchange_declare(exchange='LyamzinaLogs', exchange_type='fanout')
result = channel.queue_declare(queue='', exclusive=True)
queue_name = result.method.queue
channel.queue_bind(exchange='LyamzinaLogs', queue=queue_name)
print(' [*] Ожидание сообщения.')
def callback(ch, method, properties, body):
print(f" [x] {body}")
channel.basic_consume(
queue=queue_name, on_message_callback=callback, auto_ack=True)
channel.start_consuming()