Beispiel #1
0
        /// <summary>
        /// Handles pushing a message into a queue
        /// </summary>
        private async Task HandlePush(MqClient client, TmqMessage message, ChannelQueue queue)
        {
            //check authority
            if (_server.Authorization != null)
            {
                bool grant = await _server.Authorization.CanMessageToQueue(client, queue, message);

                if (!grant)
                {
                    if (!string.IsNullOrEmpty(message.MessageId))
                    {
                        await client.SendAsync(MessageBuilder.ResponseStatus(message, KnownContentTypes.Unauthorized));
                    }
                    return;
                }
            }

            //prepare the message
            QueueMessage queueMessage = new QueueMessage(message);

            queueMessage.Source = client;

            //push the message
            PushResult result = await queue.Push(queueMessage, client);

            if (result == PushResult.StatusNotSupported)
            {
                await client.SendAsync(MessageBuilder.ResponseStatus(message, KnownContentTypes.Unacceptable));
            }
            else if (result == PushResult.LimitExceeded)
            {
                await client.SendAsync(MessageBuilder.ResponseStatus(message, KnownContentTypes.LimitExceeded));
            }
        }