示例#1
0
        /// <summary>
        /// Return Partition -> Message
        /// </summary>
        public IEnumerable<Tuple<Int32, Message>> Load(String topic, Dictionary<Int32, Int32> offsetByPartition, Int32 blockSize)
        {
            var multifetch = new MultiFetchRequest();
            multifetch.FetchRequests = new List<FetchRequest>(offsetByPartition.Count);
            foreach (var pair in offsetByPartition)
            {
                var request = new FetchRequest();
                request.Topic = topic;
                request.Partition = pair.Key;
                request.Offset = pair.Value;
                request.BlockSize = blockSize;
                multifetch.FetchRequests.Add(request);
            }

            var response = (MultiFetchResponse) _sender.Send(multifetch);

            foreach (var fetchResponse in response.FetchResponses)
            {
                using (var messageReader = new MessageReader(new BinaryMemoryStream(fetchResponse.Data)))
                {
                    foreach (var message in messageReader.ReadAllMessages())
                        yield return new Tuple<int, Message>(fetchResponse.Partition, message);
                }
            }
        }
示例#2
0
        public static MultiFetchRequest ReadFromStream(BinaryStream buffer)
        {
            var result = new MultiFetchRequest();
            var count = buffer.Reader.ReadInt32();

            result.FetchRequests = new List<FetchRequest>(count);
            for(int i = 0; i < count; i++)
            {
                var requestType = buffer.Reader.ReadInt16();
                result.FetchRequests.Add(FetchRequest.ReadFromStream(buffer));
            }

            return result;
        }
示例#3
0
        public static MultiFetchRequest ReadFromStream(BinaryStream buffer)
        {
            var result = new MultiFetchRequest();
            var count  = buffer.Reader.ReadInt32();

            result.FetchRequests = new List <FetchRequest>(count);
            for (int i = 0; i < count; i++)
            {
                var requestType = buffer.Reader.ReadInt16();
                result.FetchRequests.Add(FetchRequest.ReadFromStream(buffer));
            }


            return(result);
        }