Beispiel #1
0
        /// <summary>
        /// 配置链接信息
        /// </summary>
        /// <param name="config"></param>
        private static void Open(MqConfig config)
        {
            if (_conn != null)
            {
                return;
            }
            lock (LockObj)
            {
                var factory = new ConnectionFactory
                {
                    //设置主机名
                    HostName = config.Host,

                    //设置心跳时间
                    RequestedHeartbeat = config.HeartBeat,

                    //设置自动重连
                    AutomaticRecoveryEnabled = config.AutomaticRecoveryEnabled,

                    //重连时间
                    NetworkRecoveryInterval = config.NetworkRecoveryInterval,

                    //用户名
                    UserName = config.UserName,

                    //密码
                    Password = config.Password,
                    //虚拟端口
                    VirtualHost = config.VirtualHost
                };
                factory.AutomaticRecoveryEnabled = true;
                factory.NetworkRecoveryInterval  = new TimeSpan(1000);
                _conn = _conn ?? factory.CreateConnection();
            }
        }
Beispiel #2
0
        public RabbitMqService(string url)
        {//amqp://yangqijian:[email protected]:5672/DBFVHost
            url = url.Replace("amqp://", "");
            var configArray = url.Split('@');
            var userAndPwd  = configArray[0];
            var ipAndPort   = configArray[1];

            MqConfig config = new MqConfig
            {
                UserName    = userAndPwd.Split(':')[0],
                Password    = userAndPwd.Split(':')[1],
                Host        = ipAndPort.Split('/')[0].Split(':')[0],
                VirtualHost = ipAndPort.Split('/')[1].TrimStart('/'),
                HeartBeat   = 60,
                AutomaticRecoveryEnabled = true
            };

            config.HeartBeat = 60;
            config.NetworkRecoveryInterval = new TimeSpan(60);

            Open(config);
        }
Beispiel #3
0
 /// <summary>
 /// 初始化链接
 /// </summary>
 /// <param name="config">配置信息</param>
 public RabbitMqService(MqConfig config)
 {
     Open(config);
 }