예제 #1
0
        /// <summary>
        /// 创建一个单例的RabbitMqClient实例。
        /// </summary>
        /// <returns>IRabbitMqClient</returns>
        public static IRabbitMqClient CreateRabbitMqClientInstance()
        {
            var rabbitMqClientContext = new RabbitMqClientContext
            {
                InstanceCode    = Guid.NewGuid().ToString(),
                ListenQueueName = RabbitMqConfigFactory.CreateRabbitMqConfigInstance().MqListenQueueName
            };

            RabbitMqClient.Instance = new RabbitMqClient
            {
                Context = rabbitMqClientContext
            };

            return(RabbitMqClient.Instance);
        }
예제 #2
0
        /// <summary>
        /// 创建一个IConnection。
        /// </summary>
        /// <returns></returns>
        internal static IConnection CreateConnection()
        {
            var mqConfigDom = RabbitMqConfigFactory.CreateRabbitMqConfigInstance(); //获取MQ的配置

            const ushort heartbeat = 60;
            var          factory   = new ConnectionFactory()
            {
                HostName                 = mqConfigDom.MqHost,
                Port                     = mqConfigDom.MqPort,
                UserName                 = mqConfigDom.MqUserName,
                Password                 = mqConfigDom.MqPassword,
                VirtualHost              = mqConfigDom.MqVirtualHost,
                RequestedHeartbeat       = heartbeat, //心跳超时时间
                AutomaticRecoveryEnabled = true       //自动重连
            };

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