RabbitMQ “Hello World” example gives “Connection Refused”

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



RabbitMQ “Hello World” example gives “Connection Refused”



II'm trying to make the "hello world" application from here: RabbitMQ Hello World



Here is the code of my producer class:


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();




And here what I get when implement this:


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



What is causing this?



I found the solution to my problem here Error in making a socket connection





For reference, Google says В соединении отказано translates to Connection Refused.
– thegrinner
Mar 15 '13 at 14:24





Does this question help with your problem? stackoverflow.com/questions/8939074/…
– thegrinner
Mar 15 '13 at 14:26





I'm sorry that didn't translate this. I didn't noticed it. well, thegrinner, that post descrybes the way of solving my problem, but I've solved it little earlier than see that post. thank you very much anyway.
– Nikitin Mikhail
Mar 16 '13 at 7:27





7 Answers
7



To deal with it I installed RabbitMQ server. If rabbitmq-server is not installed this error will be thrown.





More specifically, this error will be thrown if RabbitMQ is not running.
– Smile4ever
Oct 18 '16 at 7:08



I got this "Connection Refused" error as well:


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: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 ReceiveLogs.main(ReceiveLogs.java:14)



I had made a mistake by setting the IP address from inside /etc/rabbitmq/rabbitmq-env.conf to the wrong ip address:


/etc/rabbitmq/rabbitmq-env.conf


NODE_IP_ADDRESS=10.0.1.45



I removed this configuration parameter and the error goes away.





this. worked for me. We had set NODE_IP_ADDRESS to 127.0.0.1 so the listener were not able to connect to it, when I set the server IP address there, listeners started working.
– user55926
Apr 26 at 10:27



I solved this problem simply by executing:


sudo rabbitmq-server



Start the Rabbit MQ Server. The batch file to start this server is present under rabbitmq_server-3.6.0sbin>rabbitmq-server.bat start then it will work.



In my case it gave me the following error trying to start the server

<Rabbit intall path>rabbitmq_server-3.6.0sbin>rabbitmq-server.bat start
ERROR: epmd error for host Protocol: inet_tcp: register/listen error: econnrefused: nxdomain (non-existing domain)



<Rabbit intall path>rabbitmq_server-3.6.0sbin>rabbitmq-server.bat start
ERROR: epmd error for host Protocol: inet_tcp: register/listen error: econnrefused: nxdomain (non-existing domain)



What I did was add in my host file the following line:

127.0.0.1 localhost


host



127.0.0.1 localhost



And then the rabbitmq-server started. After this I didn't get the connection refuse error anymore. Hope this helps.


connection refuse



You have to start Rabbit MQ Serever



In windows file name: RabbitMQ Service - start



You can use this code:


import java.io.IOException;
import java.util.ResourceBundle;
import java.util.concurrent.TimeoutException;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class NewTaskController implements Runnable
private final String message;

private static final String EXCHANGE_NAME = "test";

private static final String ROUTING_KEY = "test";

public NewTaskController(final String message)
this.message = message;


@Override
public void run()

//getting data from application.properties
//for the rabbit_mq configuration

ResourceBundle mRB = ResourceBundle.getBundle("application");


System.out.println("*****NewTaskController************"+mRB.getString("rabbitmq.port"));
String rabbitmq_username = mRB.getString("rabbitmq.username");
String rabbitmq_password = mRB.getString("rabbitmq.password");
String rabbitmq_hostname = mRB.getString("rabbitmq.hostname");
int rabbitmq_port = Integer.parseInt(mRB.getString("rabbitmq.port"));
ConnectionFactory factory = new ConnectionFactory();
factory.setUsername(rabbitmq_username);
factory.setPassword(rabbitmq_password);
factory.setHost(rabbitmq_hostname);
factory.setPort(rabbitmq_port);
Connection conn;
try
conn = factory.newConnection();
Channel channel = conn.createChannel();

channel.exchangeDeclare(EXCHANGE_NAME, "direct", true);
String queueName = channel.queueDeclare().getQueue();
System.out.println(queueName);
channel.queueBind(queueName, EXCHANGE_NAME, ROUTING_KEY);
System.out.println("Producing message: " + message + " in thread: " + Thread.currentThread().getName());
channel.basicPublish(EXCHANGE_NAME, ROUTING_KEY, null, message.getBytes());

try
channel.close();
catch (TimeoutException e)
e.printStackTrace();

conn.close();
catch (IOException



application.properties file:


rabbitmq.username=guest
rabbitmq.password=guest
rabbitmq.hostname=localhost
rabbitmq.port=5672



The simple fix is indeed, rabbitmq-server, if you already have RabbitMQ installed locally.


rabbitmq-server



I encountered this issue as a firewall issue after migrating from Mac OS X Sierra to High Sierra. I already had RabbitMQ installed. However, I kept getting this Connection Refused error. I had to do the following:


Connection Refused


brew uninstall rabbitmq


brew install rabbitmq


rabbitmq-server






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS