Jul 1, 2024
pip install pika.producer.pyimport pikaconnection_parameters = pika.ConnectionParameters('localhost')
connection = pika.BlockingConnection(connection_parameters)
channel = connection.channel()
channel.queue_declare(queue='letterbox')
message = 'Hello, this is my first message'
channel.basic_publish(exchange='', routing_key='letterbox', body=message)
print(f"Sent message: {message}")
connection.close()
consumer.pyimport pikaconnection_parameters = pika.ConnectionParameters('localhost')
connection = pika.BlockingConnection(connection_parameters)
channel = connection.channel()
channel.queue_declare(queue='letterbox')
def on_message_received(ch, method, properties, body):
print(f"Received new message: {body}")
channel.basic_consume(queue='letterbox', on_message_callback=on_message_received, auto_ack=True)
print("Started consuming")
channel.start_consuming()
python consumer.pypython producer.pyممنون از تماشای شما!