Home/Learn/RabbitMQ/Default Exchange

Default Exchange

Beginner
Exchanges

Every queue is automatically bound to the default (nameless) exchange with a routing key equal to its name; publishing directly to a queue name uses this exchange implicitly.

Overview

The default exchange is a pre-declared, nameless direct exchange built into every RabbitMQ vhost. Every queue is automatically bound to it using the queue name as its routing key — you cannot add or remove this binding manually. Publishing a message with exchange="" and routingKey="my-queue" delivers it directly to the queue named "my-queue". This is the simplest point-to-point messaging pattern and is often seen in tutorials, but for production systems with multiple consumers or dynamic routing you should declare a named exchange with explicit bindings.

Publishing to the Default Exchange

Set exchange to an empty string and routing key to the queue name. Spring's RabbitTemplate.convertAndSend(queueName, message) uses this pattern under the hood when no exchange is specified.

Java — publishing via default exchange
// Java AMQP client — explicit default exchange usage
channel.basicPublish(
    "",            // empty string = default exchange
    "order.queue", // routing key = queue name
    null,
    message.getBytes()
);

// Spring RabbitTemplate shorthand (same behaviour)
@Autowired RabbitTemplate rabbitTemplate;

rabbitTemplate.convertAndSend("order.queue", orderEvent);
// Equivalent to: exchange="", routingKey="order.queue"

Limitations of the Default Exchange

The default exchange only supports exact queue-name routing. You cannot fan out to multiple queues, use wildcard routing, or apply policies like message TTL per exchange. For anything beyond simple point-to-point, declare a named exchange.

Java — default vs named exchange comparison
// Default exchange — one queue only, no routing flexibility
rabbitTemplate.convertAndSend("order.queue", event);

// Named direct exchange — same result but explicit and extensible
rabbitTemplate.convertAndSend("orders.exchange", "order.created", event);

// Named fanout exchange — delivers to ALL bound queues
// rabbitTemplate.convertAndSend("orders.fanout", "", event);
// → order-service-queue, audit-queue, notification-queue all receive it

Declaring the Default Exchange in Spring

You do not declare the default exchange — it always exists. Just declare the queue and publish with an empty exchange name. Spring AMQP's @RabbitListener can consume from a queue regardless of how messages were published.

Java — queue declaration and listener (default exchange)
@Configuration
public class RabbitConfig {

    @Bean
    public Queue orderQueue() {
        return QueueBuilder.durable("order.queue").build();
        // Automatically bound to default exchange with routing key "order.queue"
    }
}

@Component
public class OrderConsumer {

    @RabbitListener(queues = "order.queue")
    public void onOrder(OrderEvent event) {
        log.info("Received order: {}", event.getOrderId());
    }
}

Key Points to Remember

  • 1Default exchange is nameless ("") and pre-exists in every vhost — you cannot delete it
  • 2Every queue is auto-bound to the default exchange; routing key = queue name
  • 3convertAndSend(queueName, message) on RabbitTemplate uses the default exchange implicitly
  • 4Default exchange only supports exact-name routing — no wildcards, no fanout
  • 5For production, prefer named exchanges for clarity, flexibility, and testability
  • 6Default exchange bindings cannot be removed or modified — they are broker-managed

Interview Questions

Sign in to ask Aria
1

What is the default exchange in RabbitMQ and how is every queue bound to it?

EasyPivotal
2

How does convertAndSend(queueName, message) route a message?

EasyInfosys
3

What are the limitations of using the default exchange?

MediumTCS
4

Why would you prefer a named exchange over the default exchange in production?

MediumWipro
5

Can you remove a queue's binding from the default exchange?

EasyHCL

Ask Aria about Default Exchange

Your personal AI tutor — ask anything about this concept

Revision Status

Personal Notes

Sign in to save personal notes for this topic.

Discussion

Sign in to join the discussion.

Loading discussion…