Skip to content

Default Exchange

Antoine Théate edited this page Jun 5, 2025 · 4 revisions

Exchange Explanation

The default exchange is a direct exchange that has several special properties:

  • It always exists (is pre-declared)
  • Its name for AMQP 0-9-1 clients is an empty string ("")
  • When a queue is declared, RabbitMQ will automatically bind that queue to the default exchange using its (queue) name as the routing key

This provides AMQP 0-9-1 applications with a mechanism that makes it convenient to publish "directly" to a queue using only its name, even though there's still a direct exchange involved under the hood.

Code Example

Micro Service A (Acts like consumer)

var messageClientService = serviceProvider.GetRequiredService<IMessageClientBaseService>();
var exchangeConfiguration = new DefaultExchangeConfiguration("DefaultChannel");
var messageObservable = await messageClientService.ListenAsync<string>("Primary", exchangeConfiguration);
messageObservable.Subscribe(message => Console.WriteLine(message));

Micro Service B (Acts like producer)

var messageClientService = serviceProvider.GetRequiredService<IMessageClientBaseService>();
var exchangeConfiguration = new DefaultExchangeConfiguration("DefaultChannel");
await messageClientService.PushAsync("Primary", "A message to be sent", exchangeConfiguration);

Results:
When the Micro Service B pushes the message, a new line will be written in the Console of Micro Service A with the content as "A message to be sent"

Clone this wiki locally