package me.zhengjie.utils;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;


/**
 * @author wangmx
 * 连接 RabbitMq  工具类
 */
public class ConnectionUtil {

    public static Connection getConnection() {
        //定义连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        //设置服务地址
        factory.setHost("127.0.0.1");
        //端口
        factory.setPort(5672);
        //设置账号信息
        //vhost(Virtual Host)
//        factory.setVirtualHost("test");
        //用户名
        factory.setUsername("admin");
        //密码
        factory.setPassword("admin");
        //通过工厂获得与mq的连接对象
        Connection connection = null;
        try {
            connection = factory.newConnection();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return connection;
    }

}

