title: Why declare Exchange in RabbitMQ?
body: <p>I am working on a project with RabbitMQ. My code is below.</p>
  
  <p><strong>Producer:</strong> </p>
  
  <pre><code>public static void Main()
  {
      var factory = new ConnectionFactory() { HostName = "localhost" };
      using (var connection = factory.CreateConnection())
      {
          using (var channel = connection.CreateModel())
          {
              channel.QueueDeclare("hello", false, false, false, null);
  
              string message = "Hello World!";
              var body = Encoding.UTF8.GetBytes(message);
  
              channel.BasicPublish("", "hello", null, body);
              Console.WriteLine(" [x] Sent {0}", message);
          }
      }
  }
  </code></pre>
  
  <p><strong>Consumer with Exchange declared:</strong> </p>
  
  <pre><code>public static void Main()
  {
      var factory = new ConnectionFactory() { HostName = "localhost" };
      using (var connection = factory.CreateConnection())
      {
          using (var channel = connection.CreateModel())
          {
              channel.ExchangeDeclare("hello", "direct",false, false, false, null);
              channel.QueueDeclare("hello", false, false, false, null);
  
              var consumer = new QueueingBasicConsumer(channel);
              channel.BasicConsume("hello", true, consumer);
  
              Console.WriteLine(" [*] Waiting for messages." +
                                       "To exit press CTRL+C");
              while (true)
              {
                  var ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue();
  
                  var body = ea.Body;
                  var message = Encoding.UTF8.GetString(body);
                  Console.WriteLine(" [x] Received {0}", message);
              }
          }
      }
  </code></pre>
  
  <p><strong>Consumer without Exchange declared:</strong> </p>
  
  <pre><code>public static void Main()
  {
      var factory = new ConnectionFactory() { HostName = "localhost" };
      using (var connection = factory.CreateConnection())
      {
          using (var channel = connection.CreateModel())
          {
              channel.QueueDeclare("hello", false, false, false, null);
  
              var consumer = new QueueingBasicConsumer(channel);
              channel.BasicConsume("hello", true, consumer);
  
              Console.WriteLine(" [*] Waiting for messages." +
                                       "To exit press CTRL+C");
              while (true)
              {
                  var ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue();
  
                  var body = ea.Body;
                  var message = Encoding.UTF8.GetString(body);
                  Console.WriteLine(" [x] Received {0}", message);
              }
          }
      }
  </code></pre>
  
  <p>Both consumer code works well, so what's the main use of declaring exchange? I am confused. Can anyone clarify?</p>