示例#1
0
        /// <summary>
        /// Adds the client to the queue
        /// </summary>
        public async Task <QueueSubscriptionResult> AddClient(MqClient client)
        {
            foreach (IQueueAuthenticator authenticator in Server.QueueAuthenticators)
            {
                bool allowed = await authenticator.Authenticate(this, client);

                if (!allowed)
                {
                    return(QueueSubscriptionResult.Unauthorized);
                }
            }

            if (Options.ClientLimit > 0 && _clients.Count >= Options.ClientLimit)
            {
                return(QueueSubscriptionResult.Full);
            }

            QueueClient cc = new QueueClient(this, client);

            _clients.Add(cc);
            client.AddSubscription(cc);

            foreach (IQueueEventHandler handler in Server.QueueEventHandlers)
            {
                await handler.OnConsumerSubscribed(cc);
            }

            _ = Trigger();
            OnConsumerSubscribed.Trigger(cc);
            return(QueueSubscriptionResult.Success);
        }
示例#2
0
        /// <summary>
        /// Destorys the queue
        /// </summary>
        public async Task Destroy()
        {
            IsDestroyed = true;

            try
            {
                await TimeKeeper.Destroy();

                OnMessageProduced.Dispose();

                lock (PriorityMessagesList)
                    PriorityMessagesList.Clear();

                lock (MessagesList)
                    MessagesList.Clear();

                if (_ackSync != null)
                {
                    _ackSync.Dispose();
                    _ackSync = null;
                }

                if (_listSync != null)
                {
                    _listSync.Dispose();
                }

                if (_pushSync != null)
                {
                    _pushSync.Dispose();
                }

                if (_triggerTimer != null)
                {
                    await _triggerTimer.DisposeAsync();

                    _triggerTimer = null;
                }
            }
            finally
            {
                OnDestroyed?.Invoke(this);
            }

            _clients.Clear();
            OnConsumerSubscribed.Dispose();
            OnConsumerUnsubscribed.Dispose();
        }