DAS_2024_1/kosheev_maksim_lab_4/lesson1-hello-world/send.py

18 lines
484 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import pika
# Устанавливаем соединение с RabbitMQ
connection = pika.BlockingConnection(
pika.ConnectionParameters(host='localhost')
)
channel = connection.channel()
# Объявляем очередь
channel.queue_declare(queue='hello')
# Отправляем сообщение
channel.basic_publish(exchange='', routing_key='hello', body='Hello World!')
print(" [x] Sent 'Hello World!'")
# Закрываем соединение
connection.close()