简体   繁体   English

RabbitMQ:无法连接到远程计算机(RPC)

[英]RabbitMQ : Cannot connect to distant machine (RPC)

I want to connect two machines using RabbitMQ, using the Remote procedure call. 我想使用RabbitMQ通过远程过程调用连接两台计算机。 I have two machines, my local machine (address : 10.3.9.73) and a VM machine (address : 10.3.9.2) . 我有两台计算机,我的本地计算机(地址:10.3.9.73)和一台VM计算机(地址:10.3.9.2)。 These adresses are pingable. 这些地址是可ping通的。 I run the client app in my VM machine using this code : 我使用以下代码在VM计算机中运行客户端应用程序:

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. 并删除'%%',然后重新启动Rabbitmq服务器。

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 默认情况下,您可以使用guest作为登录名和密码

if this doesn't work, you should test if your client can connect to your server through the port 5672 如果这不起作用,则应测试客户端是否可以通过端口5672连接到服务器

 telnet 10.3.9.73 5672

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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