Пример #1
0
        /// <summary>
        /// 创建实例
        /// </summary>
        /// <returns></returns>
        public static IRabbitMqClient CreateInstance()
        {
            var clientContext = new RabbitMqClientContext()
            {
                ListenQueueName = MqConfigFactory.CreateConfigInstance().ListenQueueName,
                InstanceCode    = Guid.NewGuid().ToString()
            };

            return(new RabbitMqClient()
            {
                Context = clientContext
            });
        }
Пример #2
0
        public static IRabbitMqClient CreateRabbitMqClientInstance()
        {
            var rabbitMqClientContext = new RabbitMqClientContext
            {
                ListenQueueName = MqConfigFactory.CreateConfigInstance().MqListenQueueName,
                InstanceCode    = Guid.NewGuid().ToString()
            };

            RabbitMqClient.Instance = new RabbitMqClient
            {
                Context = rabbitMqClientContext
            };
            return(RabbitMqClient.Instance);
        }
Пример #3
0
        /// <summary>
        /// 创建连接
        /// </summary>
        /// <returns></returns>
        internal static IConnection CreateConnection()
        {
            var          config    = MqConfigFactory.CreateConfigInstance();
            const ushort heartbeat = 60;
            var          factory   = new ConnectionFactory()
            {
                HostName = config.Host,
                UserName = config.UserName,
                Password = config.Password,
                //RequestedHeartbeat = heartbeat,
                //AutomaticRecoveryEnabled = true
            };

            return(factory.CreateConnection());
        }
Пример #4
0
        /// <summary>
        /// 创建一个IConnection
        /// </summary>
        /// <returns></returns>
        internal static IConnection CreateConnection()
        {
            var mqConfig = MqConfigFactory.CreateConfigInstance();//获取MQ配置

            const ushort heartBeat = 60;
            var          factory   = new ConnectionFactory
            {
                HostName                 = mqConfig.MqHost,
                UserName                 = mqConfig.MqUserName,
                Password                 = mqConfig.MqPassword,
                RequestedHeartbeat       = heartBeat, //心跳超时事件
                AutomaticRecoveryEnabled = true       //自动重连
            };

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