Java连接RabbitMQ之创建连接

 

依赖包:

 1 <dependencies>
 2     <dependency>
 3       <groupId>junit</groupId>
 4       <artifactId>junit</artifactId>
 5       <version>4.12</version>
 6       <scope>test</scope>
 7     </dependency>
 8 
 9     <!-- https://mvnrepository.com/artifact/com.rabbitmq/amqp-client -->
10     <dependency>
11       <groupId>com.rabbitmq</groupId>
12       <artifactId>amqp-client</artifactId>
13       <version>5.1.2</version>
14     </dependency>
15     <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-nop -->
16     <dependency>
17       <groupId>org.slf4j</groupId>
18       <artifactId>slf4j-nop</artifactId>
19       <version>1.7.25</version>
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 }

 

转载于:https://www.cnblogs.com/gongxr/p/9639489.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值