示例#1
0
 public void HandleBasicCancel(string consumerTag)
 {
     try
     {
         ConsumerCancelled?.Invoke(this, new ConsumerEventArgs(consumerTag));
     }
     catch (Exception) { }
 }
        /// <summary>
        /// Default implementation - overridable in subclasses.</summary>
        /// <param name="consumerTags">The set of consumer tags that where cancelled</param>
        /// <remarks>
        /// This default implementation simply sets the <see cref="IsRunning"/>
        /// property to false, and takes no further action.
        /// </remarks>
        public virtual async Task OnCancel(params string[] consumerTags)
        {
            IsRunning = false;
            await ConsumerCancelled.InvokeAsync(this, new ConsumerEventArgs(consumerTags)).ConfigureAwait(false);

            foreach (string consumerTag in consumerTags)
            {
                _consumerTags.Remove(consumerTag);
            }
        }
示例#3
0
        public void HandleBasicCancelOk(string consumerTag)
        {
            lock (_consumerTagsLock)
            {
                if (_consumerTags.Contains(consumerTag))
                {
                    _consumerTags.Remove(consumerTag);
                }

                ConsumerCancelled?.Invoke(this, new ConsumerEventArgs(consumerTag));
            }
        }
示例#4
0
        /// <summary>
        /// Default implementation - overridable in subclasses.</summary>
        /// <param name="consumerTags">The set of consumer tags that where cancelled</param>
        /// <remarks>
        /// This default implementation simply sets the <see cref="IsRunning"/>
        /// property to false, and takes no further action.
        /// </remarks>
        public virtual void OnCancel(params string[] consumerTags)
        {
            IsRunning = false;
            foreach (EventHandler <ConsumerEventArgs> h in ConsumerCancelled?.GetInvocationList() ?? Array.Empty <Delegate>())
            {
                h(this, new ConsumerEventArgs(consumerTags));
            }

            foreach (string consumerTag in consumerTags)
            {
                _consumerTags.Remove(consumerTag);
            }
        }
示例#5
0
        /// <summary>
        /// Default implementation - overridable in subclasses.</summary>
        /// <param name="consumerTags">The set of consumer tags that where cancelled</param>
        /// <remarks>
        /// This default implementation simply sets the <see cref="IsRunning"/>
        /// property to false, and takes no further action.
        /// </remarks>
        public virtual async Task OnCancel(params string[] consumerTags)
        {
            IsRunning = false;
            foreach (AsyncEventHandler <ConsumerEventArgs> h in ConsumerCancelled?.GetInvocationList() ?? Array.Empty <Delegate>())
            {
                await h(this, new ConsumerEventArgs(consumerTags)).ConfigureAwait(false);
            }

            foreach (string consumerTag in consumerTags)
            {
                _consumerTags.Remove(consumerTag);
            }
        }
示例#6
0
        private void HandleCancelled(object sender, ConsumerEventArgs e)
        {
            if (Interlocked.CompareExchange(ref _cancelled, 1, 0) == 1)
            {
                return;
            }

            // empty mailbox and complete
            _mailbox.TryReceiveAll(out IList <InboundMessage> messages);
            _mailbox.Complete();

            // call event
            ConsumerCancelled?.Invoke(sender, e);
        }
        /// <summary>
        /// Called when the broker cancels the consumer due to an unexpected event, such as a
        /// queue removal, or other change, that would disconnect the consumer.
        /// </summary>
        /// <param name="consumerTag">The consumerTag that is being cancelled.</param>
        void IBasicConsumer.HandleBasicCancel(string consumerTag)
        {
            LogContext.Current = _context.LogContext;

            LogContext.Debug?.Log("Consumer Canceled: {InputAddress} - {ConsumerTag}", _context.InputAddress, consumerTag);

            foreach (var context in _pending.Values)
            {
                context.Cancel();
            }

            ConsumerCancelled?.Invoke(this, new ConsumerEventArgs(consumerTag));

            _deliveryComplete.TrySetResult(true);
            SetCompleted(TaskUtil.Completed);
        }
示例#8
0
        /// <summary>
        /// Called when the broker cancels the consumer due to an unexpected event, such as a
        /// queue removal, or other change, that would disconnect the consumer.
        /// </summary>
        /// <param name="consumerTag">The consumerTag that is being cancelled.</param>
        void IBasicConsumer.HandleBasicCancel(string consumerTag)
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Consumer Cancelled: {0}", consumerTag);
            }

            foreach (var context in _pending.Values)
            {
                context.Cancel();
            }

            ConsumerCancelled?.Invoke(this, new ConsumerEventArgs(consumerTag));

            _participant.SetComplete();
        }
示例#9
0
        /// <summary>
        /// Called when the broker cancels the consumer due to an unexpected event, such as a
        /// queue removal, or other change, that would disconnect the consumer.
        /// </summary>
        /// <param name="consumerTag">The consumerTag that is being cancelled.</param>
        void IBasicConsumer.HandleBasicCancel(string consumerTag)
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Consumer Cancelled: {0}", consumerTag);
            }

            foreach (RabbitMqReceiveContext context in _pending.Values)
            {
                context.Cancel();
            }

            ConsumerCancelled?.Invoke(this, new ConsumerEventArgs(consumerTag));

            _deliveryComplete.TrySetResult(true);
            _participant.SetComplete();
        }
示例#10
0
        /// <summary>
        /// Called when the broker cancels the consumer due to an unexpected event, such as a
        /// queue removal, or other change, that would disconnect the consumer.
        /// </summary>
        /// <param name="consumerTag">The consumerTag that is being cancelled.</param>
        void IBasicConsumer.HandleBasicCancel(string consumerTag)
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Consumer Canceled: {0}", consumerTag);
            }

            foreach (var context in _pending.Values)
            {
                context.Cancel();
            }

            ConsumerCancelled?.Invoke(this, new ConsumerEventArgs(consumerTag));

            _deliveryComplete.TrySetResult(true);
            SetCompleted(TaskUtil.Completed);
        }
示例#11
0
        private void HandleCancelled(object sender, ConsumerEventArgs e)
        {
            if (Interlocked.CompareExchange(ref _cancelled, 1, 0) == 1)
            {
                return;
            }

            // call completed on all observers
            lock (_subscriptions) {
                foreach (SubscribedObserver observer in _subscriptions)
                {
                    observer.Observer.OnCompleted();
                }
            }

            // call event
            ConsumerCancelled?.Invoke(sender, e);
        }
示例#12
0
        /// <summary>
        /// Called when the broker cancels the consumer due to an unexpected event, such as a
        /// queue removal, or other change, that would disconnect the consumer.
        /// </summary>
        /// <param name="consumerTag">The consumerTag that is being cancelled.</param>
        public void HandleBasicCancel(string consumerTag)
        {
            LogContext.Current = _context.LogContext;

            LogContext.Debug?.Log("Consumer Canceled: {InputAddress} - {ConsumerTag}", _context.InputAddress, consumerTag);

            CancelPendingConsumers();

            ConsumerCancelled?.Invoke(this, new ConsumerEventArgs(new[] { consumerTag }));

            if (_dispatcher.ActiveDispatchCount == 0)
            {
                _deliveryComplete.TrySetResult(true);
                SetCompleted(TaskUtil.Completed);
            }
            else
            {
                SetCompleted(_deliveryComplete.Task);
            }
        }
示例#13
0
 public void OnCancel(object queue)
 {
     ConsumerCancelled?.Invoke(queue);
 }
示例#14
0
 public void HandleBasicCancel(string consumerTag)
 {
     this.logger.LogInformation($"TopicSubscriber.HandleBasicCancel - consumerTag: {consumerTag}");
     ConsumerCancelled?.Invoke(this, new ConsumerEventArgs(consumerTag));
 }
示例#15
0
 /// <summary>
 /// Cancel means that an external signal has requested that this consumer should
 /// be cancelled. This is _not_ the same as when an internal consumer stops consuming
 /// because it has lost its channel/connection.
 /// </summary>
 private void Cancel()
 {
     cancelled?.Invoke(this);
     ConsumerCancelled?.Invoke(this, new ConsumerEventArgs(new [] { ConsumerTag }));
 }