pyinfra/mini_queue/get_from_queue.py
Julius Unverfehrt 0b26ab92a8 init
2022-02-14 11:35:12 +01:00

25 lines
738 B
Python

import pika
def get_message(parameters):
def callback(ch, method, properties, body):
print(" [x] Received %r" % body)
connection = pika.BlockingConnection(parameters)
channel = connection.channel()
channel.queue_declare(queue="test", durable=True)
channel.basic_consume(queue='test',
auto_ack=True,
on_message_callback=callback)
print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()
if __name__ == "__main__":
credentials = pika.PlainCredentials('user', 'bitnami')
parameters = pika.ConnectionParameters(host="172.17.0.2", port=5672, heartbeat=0, credentials=credentials)
get_message(parameters)