import pika
credentials = pika.PlainCredentials('admin', 'admin')
parameters = pika.ConnectionParameters('localhost',
5672,
'/',
credentials)
connection = pika.BlockingConnection(parameters)
channel = connection.channel()
queue_name = 'hello'
channel.queue_declare(queue=queue_name)
message = "Hello, bbb!"
channel.basic_publish(exchange='', routing_key=queue_name, body=message)
print(f" [x] Sent '{message}'")
connection.close()
import pika
credentials = pika.PlainCredentials('admin', 'admin')
parameters = pika.ConnectionParameters('localhost',
5672,
'/',
credentials)
connection = pika.BlockingConnection(parameters)
channel = connection.channel()
queue_name = 'hello'
channel.queue_declare(queue=queue_name)
def callback(ch, method, properties, body):
print(f" [x] Received {body.decode()}")
channel.basic_consume(
queue=queue_name, on_message_callback=callback, auto_ack=True)
print('[*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()