简体   繁体   中英

RabbitMQ : Cannot connect to distant machine (RPC)

I want to connect two machines using RabbitMQ, using the Remote procedure call. I have two machines, my local machine (address : 10.3.9.73) and a VM machine (address : 10.3.9.2) . These adresses are pingable. I run the client app in my VM machine using this code :

ConnectionFactory factory = new ConnectionFactory();
factory.setHost("10.3.9.73");
factory.setPort(5672);
connection = factory.newConnection();
channel = connection.createChannel();

replyQueueName = channel.queueDeclare().getQueue();
consumer = new QueueingConsumer(channel);
channel.basicConsume(replyQueueName, true, consumer);

And the server app in my local machine using this code :

ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
factory.setPort(5672);     
connection = factory.newConnection();
channel = connection.createChannel();
channel.queueDeclare(RPC_QUEUE_NAME, false, false, false, null);
channel.basicQos(1);
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume(RPC_QUEUE_NAME, false, consumer);
System.out.println(" [x] Awaiting RPC requests");

The code of the client app fails and shows this error:

"com.rabbitmq.client.AuthenticationFailureException: ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN. For details see the broker logfile."

How to solve this problem?

Can you please put the logfile content.

I think that you should to configure your login and password :

Sudo cp /usr/share/doc/rabbitmq-server-[rabbitmq version]/rabbitmq.config.example /etc/rabbitmq/rabbitmq.config 

Then search for

%%{loopback_users, []}

And remove '%%', Then restart rabbitmq server.

then you should add those following lines in your code:

factory.setUsername("guest");
factory.setPassword("guest");

by default, you can use guest as your login and password

if this doesn't work, you should test if your client can connect to your server through the port 5672

 telnet 10.3.9.73 5672

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM