Beispiel #1
0
        /// <summary>
        /// Finds and subscribes to the queue and sends response
        /// </summary>
        private async Task Subscribe(MqClient client, HorseMessage message)
        {
            HorseQueue queue = _server.FindQueue(message.Target);

            //if auto creation active, try to create queue
            if (queue == null && _server.Options.AutoQueueCreation)
            {
                QueueOptions options = QueueOptions.CloneFrom(_server.Options);
                queue = await _server.CreateQueue(message.Target, options, message, _server.DeliveryHandlerFactory, true, true);
            }

            if (queue == null)
            {
                if (message.WaitResponse)
                {
                    await client.SendAsync(message.CreateResponse(HorseResultCode.NotFound));
                }

                return;
            }

            QueueClient found = queue.FindClient(client.UniqueId);

            if (found != null)
            {
                if (message.WaitResponse)
                {
                    await client.SendAsync(message.CreateResponse(HorseResultCode.Ok));
                }

                return;
            }

            QueueSubscriptionResult result = await queue.AddClient(client);

            if (message.WaitResponse)
            {
                switch (result)
                {
                case QueueSubscriptionResult.Success:
                    await client.SendAsync(message.CreateResponse(HorseResultCode.Ok));

                    break;

                case QueueSubscriptionResult.Unauthorized:
                    await client.SendAsync(message.CreateResponse(HorseResultCode.Unauthorized));

                    break;

                case QueueSubscriptionResult.Full:
                    await client.SendAsync(message.CreateResponse(HorseResultCode.LimitExceeded));

                    break;
                }
            }
        }