2024-12-04 00:28:01 +04:00
|
|
|
|
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()
|