DAS_2024_1/mochalov_danila_lab_4/labwork/producer.py

29 lines
805 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
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()