标签:vhost 设置 factor get imp 队列 exception on() val
package com.dwz.rabbitmq.util; import java.io.IOException; import java.util.concurrent.TimeoutException; import com.rabbitmq.client.Connection; import com.rabbitmq.client.ConnectionFactory; public class ConnectionUtils { /** * 获取MQ的连接 * @return * @throws TimeoutException * @throws IOException */ public static Connection getConnection() throws IOException, TimeoutException { //定义一个连接工厂 ConnectionFactory factory = new ConnectionFactory(); //设置服务地址 factory.setHost("127.0.0.1"); //设置AMQP端口号 factory.setPort(5672); //vhost factory.setVirtualHost("/vhost_dwz"); factory.setUsername("root_dwz"); factory.setPassword("123456"); //设置网络断开时的自动重连 factory.setAutomaticRecoveryEnabled(true); //每3秒重连一次 factory.setNetworkRecoveryInterval(3000); return factory.newConnection(); } }
标签:vhost 设置 factor get imp 队列 exception on() val
原文地址:https://www.cnblogs.com/zheaven/p/11799385.html