Java连接RabbitMQ之创建连接
2021-07-01 02:04
标签:password virt pack port 创建 tps actor ret on() 依赖包: 源码: Java连接RabbitMQ之创建连接 标签:password virt pack port 创建 tps actor ret on() 原文地址:https://www.cnblogs.com/gongxr/p/9639489.html 1 dependencies>
2 dependency>
3 groupId>junitgroupId>
4 artifactId>junitartifactId>
5 version>4.12version>
6 scope>testscope>
7 dependency>
8
9
10 dependency>
11 groupId>com.rabbitmqgroupId>
12 artifactId>amqp-clientartifactId>
13 version>5.1.2version>
14 dependency>
15
16 dependency>
17 groupId>org.slf4jgroupId>
18 artifactId>slf4j-nopartifactId>
19 version>1.7.25version>
20 dependency>
21
22 dependencies>
1 package org.study.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 * 获取rabbitmq连接
11 */
12 public class ConnectionUtils {
13 public static Connection getConnection() throws IOException, TimeoutException {
14 ConnectionFactory factory = new ConnectionFactory();
15 factory.setHost("10.15.1.26");
16 factory.setPort(5672);
17 factory.setVirtualHost("/test_host");
18 factory.setUsername("admin");
19 factory.setPassword("admin");
20 Connection connection = factory.newConnection();
21 return connection;
22 }
23 }
上一篇:python基础:条件循环字符串