初始配置
添加用户
使用默认的 guest 账号登录后,可以在 Admin → Users中添加用户:
添加 Virtual Host
在Admin → Virtual Hosts 中添加虚拟机:
给用户授权
点击 Virtual Host 的名称,进入详情界面,可在Permissions中给新建的用户设置权限:
建立连接
1、新建Maven 项目
2、导入依赖
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.x2m</groupId>
<artifactId>rabbitmq</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>amqp-client</artifactId>
<version>5.21.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
3、创建工具类连接 RabbitMQ
public static Connection getConnection() {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
factory.setPort(5672);
factory.setUsername("zhuzl");
factory.setPassword("123456");
factory.setVirtualHost("/test");
Connection conn = null;
try {
conn = factory.newConnection();
} catch (IOException e) {
throw new RuntimeException(e);
} catch (TimeoutException e) {
throw new RuntimeException(e);
}
return conn;
}
4、代码层面获取连接后,在管理界面可以看到如下连接信息:
5、点击Name 可查看连接详情如下:
6、调试界面的连接信息:
评论 (0)