/// <summary>
        /// Returns messages from RabbitMQ.
        /// </summary>
        /// <param name="offset">Offset from start.</param>
        /// <param name="count">Count of messages.</param>
        /// <param name="clientId">Filter queues by client ID, empty string - do not filter.</param>
        /// <param name="messageTypeId">Filter queues by message type ID, empty string - do not filter.</param>
        /// <returns>Messages from RabbitMQ.</returns>
        public ServiceBusMessage[] GetMessages(int offset, int count, string clientId, string messageTypeId)
        {
            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(offset));
            }

            if (count < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(count));
            }

            int skipped    = 0;
            var sbMessages = new List <ServiceBusMessage>();

            IEnumerable <RabbitMQQueue> queues = FilterQueues(_managementClient.GetQueuesAsync().Result, clientId, messageTypeId);

            foreach (var queue in queues)
            {
                skipped += queue.Messages;
                if (skipped > offset)
                {
                    string _clientId;
                    string _messageTypeId;
                    _namingManager.ParseQueueName(queue.Name, out _clientId, out _messageTypeId);
                    var client = new Client()
                    {
                        ID = _clientId
                    };
                    var messageType = new MessageType()
                    {
                        ID = _messageTypeId
                    };

                    int skipInQueue         = offset > 0 ? queue.Messages - (skipped - offset) : offset;
                    int getFromQueue        = Math.Min(queue.Messages, count + skipInQueue - sbMessages.Count);
                    var getMessagesCriteria = new GetMessagesCriteria(getFromQueue, Ackmodes.ack_requeue_true);

                    IEnumerable <RabbitMQMessage> rmqMessages = _managementClient.GetMessagesFromQueueAsync(queue, getMessagesCriteria).Result.Skip(skipInQueue);
                    foreach (var rmqMessage in rmqMessages)
                    {
                        ServiceBusMessage sbMessage = _messageConverter.ConvertFromMqFormat(Convert.FromBase64String(rmqMessage.Payload), null);
                        sbMessage.Recipient   = client;
                        sbMessage.MessageType = messageType;
                        sbMessages.Add(sbMessage);
                    }

                    if (sbMessages.Count == count)
                    {
                        break;
                    }
                }
            }

            return(sbMessages.ToArray());
        }
        /// <summary>
        /// Получение сообщения для подписчика.
        /// </summary>
        /// <param name="clientId">Идентификатор клиента.</param>
        /// <param name="messageTypeId">Идентификатор типа сообщения.</param>
        /// <returns>Сообщения или null, если сообщения нет.</returns>
        public Message ReadMessage(string clientId, string messageTypeId)
        {
            MessageWithNotTypedPk result = null;

            var queueName = _namingManager.GetClientQueueName(clientId, messageTypeId);
            var message   = SharedModel.BasicGet(queueName, false);

            if (message != null)
            {
                result             = _converter.ConvertFromMqFormat(message.Body, message.BasicProperties.Headers);
                result.MessageType = new MessageType()
                {
                    ID = messageTypeId
                };
                result.__PrimaryKey = message.DeliveryTag;
            }

            return(result);
        }