title: RabbitMQ "Hello World" example gives "Connection Refused"
body: <p>II'm trying to make the "hello world" application from here: <a href="http://www.rabbitmq.com/tutorials/tutorial-one-java.html" rel="noreferrer">RabbitMQ Hello World</a></p>
  
  <p>Here is the code of my producer class:</p>
  
  <pre><code>package com.mdnaRabbit.producer;
  
  import com.rabbitmq.client.ConnectionFactory;
  import com.rabbitmq.client.Connection;
  import com.rabbitmq.client.Channel;
  
  import java.io.IOException;
  
  public class App {
  
      private final static String QUEUE_NAME = "hello";
  
      public static void main( String[] argv) throws IOException{
          ConnectionFactory factory = new ConnectionFactory();
          factory.setHost("localhost");
          Connection connection = factory.newConnection();
          Channel channel = connection.createChannel();
  
          channel.queueDeclare(QUEUE_NAME, false, false, false, null);
          String message = "Hello World!";
          channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
          System.out.println(" [x] Sent" + "'");
          channel.close();
          connection.close();
      }
  }
  </code></pre>
  
  <p>And here what I get when implement this:</p>
  
  <pre><code>Exception in thread "main" java.net.ConnectException: Connection refused
  at java.net.PlainSocketImpl.socketConnect(Native Method)
  at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
  at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
  at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
  at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
  at java.net.Socket.connect(Socket.java:579)
  at com.rabbitmq.client.ConnectionFactory.createFrameHandler(ConnectionFactory.java:445)
  at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:504)
  at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:533)
  at com.mdnaRabbit.producer.App.main(App.java:16)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:601)
  at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
  
  Process finished with exit code 1
  </code></pre>
  
  <p>What is causing this?</p>
  
  <p>I found the solution to my problem here <a href="https://stackoverflow.com/questions/8939074/error-in-making-a-socket-connection">Error in making a socket connection</a></p>