Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 2
0
        public static FetchRequest ReadFromStream(BinaryStream buffer)
        {
            var request = new FetchRequest
            {
                Topic = buffer.Reader.ReadString(),
                Partition = buffer.Reader.ReadInt32(),
                Offset = buffer.Reader.ReadInt32(),
                BlockSize = buffer.Reader.ReadInt32()
            };

            return request;
        }