赞
踩
异常信息
Exception in thread “main” java.io.IOException
at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:129)
at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:125)
at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:147)
at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:439)
at com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnectionFactory.newConnection(RecoveryAwareAMQConnectionFactory.java:65)
at com.rabbitmq.client.impl.recovery.AutorecoveringConnection.init(AutorecoveringConnection.java:160)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1216)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1173)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1131)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1294)
at util.ConnectionUtil.getConnection(ConnectionUtil.java:40)
at 基础的_自动ACK.Send.main(Send.java:27)
Caused by: com.rabbitmq.client.ShutdownSignalException: connection error; protocol method: #method<connection.close>(reply-code=530, reply-text=NOT_ALLOWED - vhost /kavito not found, class-id=10, method-id=40)
at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:66)
at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:36)
at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:502)
at com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQChannel.java:293)
at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:141)
… 9 more
工具类
public class ConnectionUtil {
private static final String HOST = “127.0.0.1”;
/**
* 这里java访问需要使用5672;
* web访问用的是15672;
*/
private static final Integer PORT = 5672;
private static final String VIRTUAL_HOST = “/kavito”;
private static final String USERNAME = “chen”;
private static final String PASSWORD = “a123”;
public static Connection getConnection() throws IOException, TimeoutException {
// 定义链接工厂
ConnectionFactory factory = new ConnectionFactory();
// 服务地址
factory.setHost(HOST);
// 端口
factory.setPort(PORT);
// 设置账号信息,用户名,密码,vhost
// 设置虚拟机,一个mq服务可以设置多个虚拟机,每个虚拟机就相当于一个独立的mq
factory.setVirtualHost(VIRTUAL_HOST);
factory.setUsername(USERNAME);
factory.setPassword(PASSWORD);
// 通过工厂获取连接
Connection connection = factory.newConnection();
return connection;
}
}
问题解决
我这边解决并非使用网上的设置权限
设置权限的参考命令
rabbitmqctl set_permissions -p “/” username “." ".” “.*”
我的问题是由于设置虚拟机导致的问题
rabbitMQ上虚拟机默认为:
而我代码里设置的虚拟机为
解决办法
第一种.将代码中的虚拟机改为
第二种.在RabbitMQ中新建一个名为 /kavito 的虚拟机 (PS:这里的名字根据自己实际来)
并给对应用户设置权限即可
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。