Esempio n. 1
0
        private List <ConsumerMessageStream> BuildStreamsForTopic(String topic, Int32 numberOfStreams)
        {
            var list             = new List <ConsumerMessageStream>();
            var partitionsNumber = GetNumberOfPartitionsForTopic(topic);

            var additional = ((partitionsNumber % numberOfStreams) == 0) ? 0 : 1;
            var step       = partitionsNumber / numberOfStreams + additional;

            for (int i = 0; i < numberOfStreams; i++)
            {
                var startingFrom = i * step;
                var count        = step;

                if (startingFrom + count > partitionsNumber)
                {
                    count = partitionsNumber - startingFrom;
                }

                var messageStream = new ConsumerMessageStream(_stateStorageDirectory, _brokerAddress, _configuration, _context);
                messageStream.Topic      = topic;
                messageStream.Partitions = GetPartitions(i * step, count);
                list.Add(messageStream);
            }

            return(list);
        }
Esempio n. 2
0
        private List<ConsumerMessageStream> BuildStreamsForTopic(String topic, Int32 numberOfStreams)
        {
            var list = new List<ConsumerMessageStream>();
            var partitionsNumber = GetNumberOfPartitionsForTopic(topic);

            var additional = ((partitionsNumber % numberOfStreams) == 0) ? 0 : 1;
            var step = partitionsNumber / numberOfStreams + additional;

            for (int i = 0; i < numberOfStreams; i++)
            {
                var startingFrom = i * step;
                var count = step;

                if (startingFrom + count > partitionsNumber)
                    count = partitionsNumber - startingFrom;

                var messageStream = new ConsumerMessageStream(_stateStorageDirectory, _brokerAddress, _configuration, _context);
                messageStream.Topic = topic;
                messageStream.Partitions = GetPartitions(i*step, count);
                list.Add(messageStream);
            }

            return list;
        }