package me.zhengjie.utils;

import com.rabbitmq.client.Connection;
//import com.rabbitmq.client.ConnectionFactory;
import org.springframework.amqp.rabbit.connection.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;


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

//    public static Connection getConnection() {
//        //定义连接工厂
//        ConnectionFactory factory = new ConnectionFactory();
//        //设置服务地址
//        factory.setHost("10.208.19.5");//10.21.39.1 10.208.19.6
//        //端口
//        factory.setPort(11673);//56720 11672
//        //设置账号信息
//        //vhost(Virtual Host)
////        factory.setVirtualHost("schedule_produce");
//        //用户名
//        factory.setUsername("rabbit");//admin usermq
//        //密码
//        factory.setPassword("Rabbit!@#$123");//123456  User!@#$mq
//        //通过工厂获得与mq的连接对象
//        Connection connection = null;
//        try {
//            connection = factory.newConnection();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//        return connection;
//    }

//    @Bean(name = "firstConnectionFactory")
//    public ConnectionFactory firstConnectionFactory(@Value("${my.rabbitmq.host}") String host,
//                                                    @Value("${my.rabbitmq.port}") int port,
//                                                    @Value("${my.rabbitmq.username}") String username,
//                                                    @Value("${my.rabbitmq.password}") String password,
//                                                    @Value("${my.rabbitmq.first.virtual-host}") String vHost) {
//        CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
//        connectionFactory.setHost(host);
//        connectionFactory.setPort(port);
//        connectionFactory.setUsername(username);
//        connectionFactory.setPassword(password);
//        connectionFactory.setVirtualHost(vHost);
//        return connectionFactory;
//    }
//
//    @Bean(name = "secondConnectionFactory")
//    public ConnectionFactory secondConnectionFactory(@Value("${my.rabbitmq.host}") String host,
//                                                    @Value("${my.rabbitmq.port}") int port,
//                                                    @Value("${my.rabbitmq.username}") String username,
//                                                    @Value("${my.rabbitmq.password}") String password,
//                                                    @Value("${my.rabbitmq.second.virtual-host}") String vHost) {
//        CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
//        connectionFactory.setHost(host);
//        connectionFactory.setPort(port);
//        connectionFactory.setUsername(username);
//        connectionFactory.setPassword(password);
//        connectionFactory.setVirtualHost(vHost);
//        return connectionFactory;
//    }

}

