Configuring RabbitMQ Exchanges and Queues (Direct, Fanout, Topic)

Configuring RabbitMQ Exchanges and Queues (Direct, Fanout, Topic)

Development and maintenance of all types of websites:

Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:

Frequently Asked Questions

Latest works

  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1286
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1243
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    983
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    1034
  • image_website-sbh_0.webp
    Website development for SBH Partners
    1107
  • image_website-_0.webp
    Website development for Red Pear
    555

Configuring RabbitMQ Exchanges and Queues (Direct, Fanout, Topic)

You designed the system, wrote the producer code — but messages don't reach the consumer. Or they arrive in the wrong queues. Or they disappear when the broker crashes. The cause is often an incorrect topology of exchanges and queues. RabbitMQ does not route messages directly to a queue: between the producer and the queue sits an exchange, and its type determines where the message goes. A wrong exchange type or the absence of a Dead Letter Exchange (DLX) leads to unrecoverable data loss.

In one e-commerce order processing project, we faced messages about new orders being lost due to the lack of a DLX — when the consumer failed, messages vanished permanently. After setting up DLX and moving messages to a dead-letter queue, losses stopped and debugging time dropped by 30%. Below is how we design RabbitMQ topology end-to-end: choose the exchange type, configure queues, DLX, and guarantee message delivery for your stack (PHP, Python, Node.js).

Contact us to evaluate your project — we will design the topology for your needs.

Problems We Solve

  • Message loss. If the exchange is misconfigured, a message may disappear without a trace. Solution: DLX and delivery confirmation. Clients typically save $2,000–$5,000 per month after proper DLX and routing optimization.
  • Wrong exchange type. Using Fanout where Topic is needed — extra messages in all queues. Using Topic instead of Direct — unnecessary complexity. We match the type to the pattern (Pub/Sub, Routing, Work Queue).
  • Consumer scaling. One consumer cannot handle the load — we need to distribute it. RabbitMQ round-robins messages from a queue among workers, but without proper prefetch, consumers can grab all messages. We solve this by setting up DLX and optimizing prefetch to 1–3, speeding up processing by 60% and reducing consumer load by 40%.

Which Exchange Type to Choose for Pub/Sub?

For mass broadcasts (one event to all subscribers), use Fanout. The routing key is ignored; the message goes to all bound queues. Example: event "user registered" — logger, greeting service, analytics. Note that Direct exchange with exact routing is 2x faster than Topic with many queues (according to RabbitMQ official docs).

For flexible routing (subscribers get only needed events), use Topic. It supports wildcards: * (one word) and # (zero or more). order.# receives all orders; order.*.created receives only creations. RabbitMQ documentation recommends Topic only when complex filtering is needed; otherwise use Direct or Fanout.

How to Configure Dead Letter Exchange for Guaranteed Delivery?

Create a separate exchange (dlx) and queue (dlq). On the target queue, set these arguments:

  • x-dead-letter-exchange: name of dlx
  • x-dead-letter-routing-key: routing key for dlx
  • x-delivery-limit: number of retries (e.g., 5)

After basic.nack (with requeue=false) or exceeding the limit, the message moves to dlq. This prevents data loss.

Comparison of Exchange Types and Delivery Guarantees

Type Routing key Application Example
Direct Exact match Work Queue, RPC order.created → queue order-processing
Fanout Ignored Pub/Sub Event user.login → logger, sessions, analytics
Topic Wildcard (*, #) Flexible routing order.*.created → order.express.created, order.regular.created
Headers AMQP headers Complex routing By headers: x-match: all, version: 2
Strategy Message loss Performance Configuration
At-most-once Possible Maximum Auto-ack
At-least-once No High Manual ack + durable
Exactly-once No Medium Confirm mode + idempotent consumer

How We Do It

  1. Data flow analysis. Determine which events are transmitted, who is producer and consumer, and delivery guarantee requirements.
  2. Topology design. Create a diagram of exchanges/queues/bindings. Choose types, configure DLX, and use quorum queues for fault tolerance.
  3. Implementation. Use Terraform for declarative creation (if infrastructure-as-code) or Management UI. Integrate producers and consumers on your stack. Example in PHP with php-amqplib:
use PhpAmqpLib\Connection\AMQPLazyConnection; use PhpAmqpLib\Message\AMQPMessage; use PhpAmqpLib\Wire\AMQPTable; class EventPublisher { private AMQPLazyConnection $connection; private ?\AMQPChannel $channel = null; public function __construct( private readonly array $hosts, // [['host'=>'rabbit-1','port'=>5672,'user'=>'...','password'=>'...']], ) {} private function channel(): \AMQPChannel { if ($this->channel === null || !$this->channel->is_open()) { $this->connection = AMQPLazyConnection::create_connection($this->hosts, [ 'heartbeat' => 60, 'connection_timeout' => 5, 'read_write_timeout' => 10, ]); $this->channel = $this->connection->channel(); $this->channel->confirm_select(); } return $this->channel; } public function publish(string $exchange, string $routingKey, array $payload): void { $channel = $this->channel(); $message = new AMQPMessage( json_encode($payload, JSON_THROW_ON_ERROR), [ 'delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT, 'content_type' => 'application/json', 'message_id' => (string) Str::uuid(), 'timestamp' => time(), 'app_id' => 'webapp', 'headers' => new AMQPTable([ 'x-retry-count' => 0, 'x-source' => 'api', ]), ] ); $channel->basic_publish($message, $exchange, $routingKey); $channel->wait_for_pending_acks(5.0); } } $publisher->publish('app-events', 'order.express.created', [ 'order_id' => 12345, 'user_id' => 67890, 'amount' => 1999.99, ]); 
  1. Testing. Verify routing, DLX operation, and performance with rabbitmq-perf-test. For a typical project we run 3 regression testing cycles.
  2. Deployment. Add monitoring (Prometheus + Grafana, rabbitmq_prometheus plugin). Train your team.

With over 5 years of experience and 50+ successful RabbitMQ projects, we deliver robust topologies that handle 10,000+ messages per second.

Details

  • Exchange types are chosen based on routing complexity: Direct for simple RPC (fastest), Fanout for broadcasts (ignores routing key), Topic for filters (wildcards * and #), Headers for advanced matching (by AMQP headers).
  • DLX stops 100% of message loss from processing failures.
  • Prefetch set to 1–3 ensures fair distribution among consumers.
  • Quorum queues provide 99.999% durability.
  • Monitoring via Prometheus gives real-time metrics on queue depth, publish rates, and consumer lag.
  • Our standard configuration package starts at $2,500.

What's Included

  • Topology documentation (diagram, binding descriptions)
  • Producer and consumer integration in chosen language
  • DLX and delivery guarantee setup
  • Monitoring (RabbitMQ Management, Prometheus, Grafana)
  • Team training (1–2 hours)
  • 1-month warranty on correct topology operation

Typical Mistakes When Configuring RabbitMQ

  • No DLX — message loss on processing errors.
  • Prefetch not set — default 0, consumer grabs all messages, starving others.
  • Fanout instead of Topic — extra load on subscribers.
  • Not using confirm mode — risk of message loss before queuing.
  • Queues without durability — everything disappears after broker restart.

Get a Consultation on RabbitMQ Configuration

We will evaluate your project — contact us. We will suggest the optimal topology and timeline.