赞
踩
这里可以看见: connection error; protocol method: #method<connection.close>(reply-code=530, reply-text=NOT_ALLOWED - access to vhost '/' refused for user 'admin', class-id=10, method-id=40)
代码如下
- package lanlan.Simple;
-
- import com.rabbitmq.client.Channel;
- import com.rabbitmq.client.Connection;
- import com.rabbitmq.client.ConnectionFactory;
-
- import java.io.IOException;
- import java.util.concurrent.TimeoutException;
-
- public class sheng {
- //所有中间键技术都是基于tcp/ip协议之上来构建,只不过rabbitma是遵循ampq协议
- public static void main(String[] args) throws IOException, TimeoutException {
- //1:创建连接工程
- ConnectionFactory connectionFactory = new ConnectionFactory();
- connectionFactory.setHost("101.35.114.14");
- connectionFactory.setPort(5672);
- connectionFactory.setUsername("admin");
- connectionFactory.setPassword("admin");
- connectionFactory.setVirtualHost("/");
- //为下面提供对象
- Connection connection = null;
- Channel channel = null;
- try{
- //2:创建连接connnction
- connection = connectionFactory.newConnection("客户端看见的消息");
- //3:通过连接获取通道
- channel = connection.createChannel();
- //4:通过创建交换机,声明队列。绑定关系。路由key,发送消息,和接收消息
- String queueName = "queuejin";
- /*
- 参数1:队列名称
- 参数2:是否持久化,
- 参数3:排他性,是否独占独立
- 参数4:是否自动删除,一般不自动删除
- 参数5:携带参数,后面有用到
- * */
- channel.queueDeclare(queueName,false,false,false,null);
- //5:准备消息内容
- String message ="jinzhng!!!!";
- //6:发送出去给队列
- channel.basicPublish("",queueName,null,message.getBytes());
- System.err.println("发送消息成功");
- } catch (IOException | TimeoutException e) {
- e.printStackTrace();
- } finally {
- //7:关闭通道
- if (channel!=null&& channel.isOpen()){
- channel.close();
- }
- //8:关闭连接
- if (connection !=null && connection.isOpen()){
- connection.close();
- }
- }
- }
- }
解决方法:可以看见我是使用admin去登录的mq的管理但是这里我的admin其实是没有管理权限的
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。