DAS_2024_1/mochalov_danila_lab_4/labwork/producer.py

29 lines
805 B
Python
Raw Normal View History

2024-10-30 20:28:03 +04:00
import pika
import time
def produce():
connection = pika.BlockingConnection(
pika.ConnectionParameters(
host='localhost',
port=5672
)
)
channel = connection.channel()
channel.exchange_declare(exchange='game_exchange', exchange_type='fanout')
messages = [
"Вышла новая игра: Brotato",
"Ваш друг играет в Cult of the Lamb",
"Ваша игра из списка желаемого продается со скидкой!"
]
while True:
for message in messages:
channel.basic_publish(exchange='game_exchange', routing_key='', body=message)
print(f'Отправлено: {message}')
time.sleep(1)
if __name__ == "__main__":
produce()