我已经在我的windows7机器上安装了“erlang”和“rabbitmq”。但是当我尝试运行这段代码时,我得到了一个异常。
package com.rabbitmq;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
public class SendMessage {
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("UTF-8"));
System.out.println(" [x] Sent '" + message + "'");
channel.close();
connection.close();
}
}
我得到了这个例外。
线程"main"出现异常com. rabbitmq. client. AuthenticationFailureException:ACCESS_REFUSED-使用身份验证机制PLAIN拒绝登录。有关详细信息,请参阅代理日志文件。
这是日志:
2016年4月11日::12:45:06 ===添加vhost 'localhost'
=信息报告==== 2016年4月11日::14:08:52 ===接受AMQP连接(127.0.0.1:55327-> 127.0.0.1:5672)<0.360.0> (127.0.0.1:55327 -> 127.0.0.1:5672)
=错误报告==== 2016年4月11日::14:08:52 === AMQP连接错误(127.0.0.1:55327-> 127.0.0.1:5672,状态:<0.360.0>开始): starting):
=信息报告==== 2016年4月11日::14:08:52 ===关闭AMQP连接(127.0.0.1:55327-> 127.0.0.1:5672)<0.360.0> (127.0.0.1:55327 -> 127.0.0.1:5672)
当我尝试列出用户时,我没有得到任何现有用户,add_user也无法在cmd link中工作
3条答案
按热度按时间de90aj5v1#
在您的ConnectionFactory中,您需要设置您的用户名和密码,如果您已经创建了任何用户名和密码,或者您可以使用默认用户“guest”和密码“guest”,只能从localhost访问。
myzjeezk2#
您可以创建新用户(userA)和密码(userA123)。
并设置
在发送者和接收者类中。
zynd9foi3#
在严格遵循官方helloworld指南的同时遇到这个错误消息有点令人烦恼。
通过一些研究,以下是对我有效的方法:
在Web管理界面添加新虚拟主机:
从web管理界面添加新用户:
授予用户虚拟主机访问权限:
(点击用户名进入详情页)