Junior — Middle
Have you had experience working with RabbitMQ message broker?
sobes.tech AI
Answer from AI
Yes, I have worked with RabbitMQ in Python projects. RabbitMQ is a message broker that allows applications to communicate asynchronously through queues. In Python, the pika library is often used to work with RabbitMQ.
Here's an example of a simple sender and receiver:
import pika
# Sender
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()
channel.queue_declare(queue='hello')
channel.basic_publish(exchange='', routing_key='hello', body='Hello, RabbitMQ!')
connection.close()
# Receiver
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()
channel.queue_declare(queue='hello')
def callback(ch, method, properties, body):
print(f"Received message: {body.decode()}")
channel.basic_consume(queue='hello', on_message_callback=callback, auto_ack=True)
channel.start_consuming()
This approach allows building distributed systems with reliable message delivery.