private static async Task <int> FetchNumberOfNodesAsync(IRabbitMQApi api)
        {
            var response = await api.GetOverviewAsync();

            if (!response.IsSuccessStatusCode)
            {
                throw new CliException(DefaultErrorMessage +
                                       $"{ response.StatusCode } - { response.ReasonPhrase}.");
            }

            JObject json  = JObject.Parse(response.Content);
            var     nodes = json.SelectTokens("$.listeners[?(@.protocol == 'amqp')]");

            var numberOfNodes = nodes?.Count();

            if (numberOfNodes == null)
            {
                throw new CliException(DefaultErrorMessage +
                                       "Could not fetch number of nodes in this cluster.");
            }

            if (numberOfNodes == 0)
            {
                throw new CliException(DefaultErrorMessage +
                                       "No node is listening to amqp comunication in this cluster.");
            }

            return(numberOfNodes.Value);
        }
        private static async Task <string> PrepareBodyAsync(IRabbitMQApi api, string pattern)
        {
            var nodes = await FetchNumberOfNodesAsync(api);

            var mirrors = CalculateNumberOfMirrors(nodes);

            return(BuildPayload(mirrors, pattern));
        }
 public MessagesController(IRabbitMQApi rabbitMqApi)
 {
     _rabbitMqApi = rabbitMqApi;
 }