Example #1
0
        public static MqConfigDom CreateConfigDomInstance()
        {
            if (_configDom == null)
            {
                _configDom = new MqConfigDom()
                {
                    MqHost        = ConfigurationManager.AppSettings["MqHost"],
                    MqUserName    = ConfigurationManager.AppSettings["MqUserName"] ?? "guest",
                    MqPassword    = ConfigurationManager.AppSettings["MqPassword"] ?? "guest",
                    MqVirtualHost = ConfigurationManager.AppSettings["MqVirtualHost"] ?? "/"
                };
            }

            return(_configDom);
        }
Example #2
0
        public static IConnection CreateConnection(MqConfigDom mqConfigCom = null)
        {
            if (mqConfigCom == null)
            {
                mqConfigCom = MqConfigComFactory.CreateConfigDomInstance(); //获取MQ的配置
            }

            const ushort heartbeat = 60;
            var          factory   = new ConnectionFactory()
            {
                HostName = mqConfigCom.MqHost,
                UserName = mqConfigCom.MqUserName,
                Password = mqConfigCom.MqPassword,
                //心跳超时时间,如果是单节点,不设置这个值是没有问题的
                //但如果连接的是类似HAProxy虚拟节点的时候就会出现TCP被断开的可能性
                RequestedHeartbeat       = heartbeat,
                AutomaticRecoveryEnabled = true, //自动重连
                Port        = AmqpTcpEndpoint.UseDefaultPort,
                VirtualHost = mqConfigCom.MqVirtualHost
            };

            return(factory.CreateConnection());//创建连接对你
        }