Inheritance: IDisposable
コード例 #1
0
ファイル: PartitionConsumer.cs プロジェクト: paralect/brod
        /// <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
ファイル: MessagesBlock.cs プロジェクト: paralect/brod
 /// <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;
     }
 }