Пример #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
 /// <summary>
 /// Read messages from this message block
 /// </summary>
 public IEnumerable<Message> ReadMessages()
 {
     using (var reader = new MessageReader(new BinaryMemoryStream(Data)))
     {
         Message message;
         while ((message = reader.ReadMessage()) != null)
             yield return message;
     }
 }