Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RabbitMqConsumerChannel" /> class
        /// </summary>
        /// <param name="channelFactory">A <see cref="IChannelFactory" /> used to construct the <see cref="IModel" /> representing Rabbit MQ channel</param>
        /// <param name="mtsChannelSettings">The mts channel settings</param>
        /// <param name="channelSettings">The channel settings</param>
        /// <param name="connectionStatus">The connection status</param>
        public RabbitMqPublisherChannel(IChannelFactory channelFactory, IMtsChannelSettings mtsChannelSettings, IRabbitMqChannelSettings channelSettings, IConnectionStatus connectionStatus)
        {
            Guard.Argument(channelFactory, nameof(channelFactory)).NotNull();
            Guard.Argument(mtsChannelSettings, nameof(mtsChannelSettings)).NotNull();
            Guard.Argument(channelSettings, nameof(channelSettings)).NotNull();
            Guard.Argument(connectionStatus, nameof(connectionStatus)).NotNull();

            _channelFactory = channelFactory;

            _mtsChannelSettings = mtsChannelSettings;

            _channelSettings = channelSettings;

            _useQueue = false;
            if (channelSettings.MaxPublishQueueTimeoutInMs > 0 || channelSettings.PublishQueueLimit > 0)
            {
                _useQueue            = true;
                _msgQueue            = new ConcurrentQueue <PublishQueueItem>();
                _queueLimit          = channelSettings.PublishQueueLimit > 1 ? _channelSettings.PublishQueueLimit : -1;
                _queueTimeout        = channelSettings.MaxPublishQueueTimeoutInMs >= 10000 ? _channelSettings.MaxPublishQueueTimeoutInMs : 15000;
                _queueTimer          = new SdkTimer(new TimeSpan(0, 0, 5), new TimeSpan(0, 0, 1));
                _queueTimer.Elapsed += OnTimerElapsed;
                _queueTimer.FireOnce(new TimeSpan(0, 0, 5));
            }
            _shouldBeOpened = 0;

            UniqueId = _channelFactory.GetUniqueId();

            _connectionStatus = (ConnectionStatus)connectionStatus;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="RabbitMqConsumerChannel"/> class
        /// </summary>
        /// <param name="channelFactory">A <see cref="IChannelFactory"/> used to construct the <see cref="IModel"/> representing Rabbit MQ channel</param>
        /// <param name="mtsChannelSettings"></param>
        /// <param name="channelSettings"></param>
        public RabbitMqConsumerChannel(IChannelFactory channelFactory,
                                       IMtsChannelSettings mtsChannelSettings,
                                       IRabbitMqChannelSettings channelSettings)
        {
            Guard.Argument(channelFactory, nameof(channelFactory)).NotNull();
            Guard.Argument(mtsChannelSettings, nameof(mtsChannelSettings)).NotNull();

            _channelFactory     = channelFactory;
            _mtsChannelSettings = mtsChannelSettings;
            _channelSettings    = channelSettings;

            _queueName = _mtsChannelSettings.ChannelQueueName;

            _shouldBeOpened = 0;

            UniqueId              = _channelFactory.GetUniqueId();
            _healthTimer          = new SdkTimer(new TimeSpan(0, 0, _timerInterval), new TimeSpan(0, 0, 1));
            _healthTimer.Elapsed += OnTimerElapsed;
        }