当前位置:   article > 正文

【RabbitMQ】连接RabbitMQ异常: com.rabbitmq.client.ShutdownSignalException: connection error; protocol meth

com.rabbitmq.client.shutdownsignalexception: connection error; protocol meth

测试该工具类:

 
  1. package com.wj.utils;

  2.  
  3. import com.rabbitmq.client.Connection;

  4. import com.rabbitmq.client.ConnectionFactory;

  5.  
  6. import java.io.IOException;

  7. import java.util.concurrent.TimeoutException;

  8.  
  9. /**

  10. * @创建人 wj

  11. * @创建时间 2018/11/5

  12. * @描述

  13. */

  14. public class ConnectionUtil {

  15. private static final String host = "localhost";

  16. private static final int port = 5672;

  17. private static final String username="wj";

  18. private static final String password="pwd";

  19.  
  20.  
  21. /**

  22. * 获取RabbitMQ Connection连接

  23. * @return

  24. * @throws IOException

  25. * @throws TimeoutException

  26. */

  27. public static Connection getConnection() throws IOException, TimeoutException {

  28. ConnectionFactory connectionFactory = new ConnectionFactory();

  29. connectionFactory.setHost(host);

  30. connectionFactory.setPort(port);

  31. connectionFactory.setUsername(username);

  32. connectionFactory.setPassword(password);

  33. return connectionFactory.newConnection();

  34. }

  35. }

异常:

 
  1. Exception in thread "main" java.io.IOException

  2. at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:106)

  3. at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:102)

  4. at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:124)

  5. at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:378)

  6. at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:678)

  7. at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:722)

  8. at upsmart.zhsen.ServerProducer.main(ServerProducer.java:33

  9.  
  10. Caused by: com.rabbitmq.client.ShutdownSignalException: connection error; protocol method: #method<connection.close>(reply-code=530, reply-text=NOT_ALLOWED - access to vhost '/' refused for user 'wj', class-id=10, method-id=40)

解决方法:

输入:rabbitmqctl set_permissions -p "/" username ".*" ".*" ".*"

 

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

闽ICP备14008679号