0

I am new to RabbitMQ and trying out simple example on it. Below is my java source:

import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.Channel;

public class Send {

  private final static String QUEUE_NAME = "hello";

  public static void main(String[] argv) throws Exception {

    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 '" + message + "'");

    channel.close();
    connection.close();
  }
}

And am getting below error:

Exception in thread "main" java.net.ConnectException: Connection refused: connect

at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
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.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at com.rabbitmq.client.impl.FrameHandlerFactory.create(FrameHandlerFactory.java:32)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:588)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:612)
at .Send.main(Send.java:15)

Any suggestions please?

  • Is RabbitMQ server on localhost up and running? In addition, it looks like you are using default guest:guest credentials which are banned (see question looks similar to this one: http://stackoverflow.com/questions/22850546/cant-access-rabbitmq-web-management-interface-after-fresh-install, can you access with the same guest credentials web management interface)? – pinepain Oct 24 '14 at 06:22

1 Answers1

1

Do you have your RabbitMQ server installed?

Also do you have the rabbitmq-client.jar and its dependencies on the classpath?

Try running this from your terminal:

java -cp .:commons-io-1.2.jar:commons-cli-1.1.jar:rabbitmq-client.jar Send
ltalhouarne
  • 4,586
  • 2
  • 22
  • 31
  • 1
    Had some issue with system, not able establish connection. Now its fine, thanks for the command :) –  Oct 28 '14 at 16:44