title: Connecting RabbitMQ Using C#
body: <p>I am using the sample code available at internet but I am getting an exception and I am not able to solve this error.</p>
  
  <p>I am getting this exception </p>
  
  <blockquote>
    <p>BrokerUnreachableExceptionCaught None of the specified endpoints were reachable</p>
  </blockquote>
  
  <p>No idea how to resolve this error. There are so many links that have posted the encounter of error but none of them have it's resolution. Please help me regarding this. Your suggestions will be helpful to me.. Please help as soon as possible.</p>
  
  <p>Some links</p>
  
  <ul>
  <li><a href="http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/2012-September/022407.html" rel="nofollow">http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/2012-September/022407.html</a></li>
  <li><a href="http://comments.gmane.org/gmane.comp.networking.rabbitmq.general/18329" rel="nofollow">http://comments.gmane.org/gmane.comp.networking.rabbitmq.general/18329</a></li>
  </ul>
  
  <p>Code:</p>
  
  <pre><code>try
  {
      ConnectionFactory factory = new ConnectionFactory();
      factory.UserName = "user";
      factory.Password = "password";
      factory.VirtualHost = "/";
      factory.Protocol = Protocols.FromEnvironment();
      factory.HostName = "localhost";
      factory.Port = AmqpTcpEndpoint.UseDefaultPort;
      IConnection conn = factory.CreateConnection();
  
      //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);
      //    }
      //}
  }
  catch
  {
  }
  </code></pre>