依赖包:
12 3 8 9 10junit 4junit 54.12 6test 711 15 16com.rabbitmq 12amqp-client 135.1.2 1417 21 22org.slf4j 18slf4j-nop 191.7.25 20
源码:
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 }