RabbitMQ is a popular message broker system that uses the AMQP (Advanced Message Queuing Protocol). It allows applications to exchange messages asynchronously, ensuring reliability and scalability.
- Producer – Sends messages to the broker (RabbitMQ).
- Exchange – Distributes messages to queues.
- Queue – Stores messages awaiting processing.
- Consumer – Receives messages from the queue.
- Direct Exchange
- Fanout Exchange
- Topic Exchange
- Headers Exchange
import pika
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()
channel.exchange_declare(exchange='direct_logs', exchange_type='direct')
routing_key = 'error'
message = "Critical error occurred!"
channel.basic_publish(exchange='direct_logs', routing_key=routing_key, body=message)
print(f" [x] Sent '{message}' with routing key '{routing_key}'")
connection.close()def callback(ch, method, properties, body):
print(f" [x] Received {body.decode()}")
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()
channel.queue_declare(queue='error_queue')
channel.queue_bind(exchange='direct_logs', queue='error_queue', routing_key='error')
channel.basic_consume(queue='error_queue', on_message_callback=callback, auto_ack=True)
print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()- Exchanges – The mechanism for routing messages in RabbitMQ.
- Direct Exchange – Routes messages by exact key.
- Fanout Exchange – Broadcasts messages to all queues.
- Topic Exchange – Routes messages based on patterns.
- Headers Exchange – Routes messages based on headers.
RabbitMQ — это популярная система брокера сообщений, использующая протокол AMQP (Advanced Message Queuing Protocol). Он позволяет приложениям обмениваться сообщениями в асинхронном режиме, обеспечивая надёжность и масштабируемость.
- Producer (издатель) – отправляет сообщения в брокер (RabbitMQ).
- Exchange (обменник) – распределяет сообщения по очередям.
- Queue (очередь) – хранит сообщения, ожидающие обработки.
- Consumer (подписчик) – получает сообщения из очереди.
- Direct Exchange (Прямой обменник)
- Fanout Exchange (Широковещательный обменник)
- Topic Exchange (Тематический обменник)
- Headers Exchange (Заголовочный обменник)
- Exchanges – механизм маршрутизации сообщений в RabbitMQ.
- Direct Exchange – направляет сообщения по точному ключу.
- Fanout Exchange – широковещательная рассылка.
- Topic Exchange – маршрутизация по шаблону.
- Headers Exchange – маршрутизация на основе заголовков.