当前位置:   article > 正文

关于rabbitMQ factory.newConnection()报错com.rabbitmq.client.ShutdownSignalException_factory.newconnection();

factory.newconnection();

关于rabbitMQ: factory.newConnection()报错com.rabbitmq.client.ShutdownSignalException

  1. 异常信息

    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

  2. 工具类

    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;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18

    }

  3. 问题解决
    我这边解决并非使用网上的设置权限

    设置权限的参考命令
    rabbitmqctl set_permissions -p “/” username “." ".” “.*”

我的问题是由于设置虚拟机导致的问题
rabbitMQ上虚拟机默认为:
在这里插入图片描述
而我代码里设置的虚拟机为
在这里插入图片描述

解决办法
第一种.将代码中的虚拟机改为
在这里插入图片描述
第二种.在RabbitMQ中新建一个名为 /kavito 的虚拟机 (PS:这里的名字根据自己实际来)
在这里插入图片描述
并给对应用户设置权限即可
在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/484412
推荐阅读
相关标签
  

闽ICP备14008679号