赞
踩
package com.wj.utils;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import java.io.IOException;
import java.util.concurrent.TimeoutException;
/**
* @创建人 wj
* @创建时间 2018/11/5
* @描述
*/
public class ConnectionUtil {
private static final String host = "localhost";
private static final int port = 5672;
private static final String username="wj";
private static final String password="pwd";
/**
* 获取RabbitMQ Connection连接
* @return
* @throws IOException
* @throws TimeoutException
*/
public static Connection getConnection() throws IOException, TimeoutException {
ConnectionFactory connectionFactory = new ConnectionFactory();
connectionFactory.setHost(host);
connectionFactory.setPort(port);
connectionFactory.setUsername(username);
connectionFactory.setPassword(password);
return connectionFactory.newConnection();
}
}
Exception in thread "main" java.io.IOException
at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:106)
at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:102)
at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:124)
at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:378)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:678)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:722)
at upsmart.zhsen.ServerProducer.main(ServerProducer.java:33
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 ".*" ".*" ".*"
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。