public void WriteStreamState(StreamState state) { if (state == null) throw new ArgumentNullException("state"); foreach (var pair in state.OffsetByPartition) WriteStreamState(state.Topic, state.Group, pair.Key, pair.Value); }
/// <summary> /// Write state for only specified partition. /// </summary> public void WriteStreamState(StreamState state, Int32 partition) { WriteStreamState(state.Topic, state.Group, partition, state.OffsetByPartition[partition]); }
private void Start() { _started = true; _stateStorage = new ConsumerStateStorage(_stateStorageDirectory); _streamState = _stateStorage.ReadStreamState(Topic, "default-group", Partitions); var task = Task.Factory.StartNew(() => { var consumer = new PartitionConsumer(_brokerAddress, _context); var offsetByPartition = new Dictionary<Int32, Int32>(); foreach (var pair in _streamState.OffsetByPartition) offsetByPartition.Add(pair.Key, pair.Value); while(true) { // If we already have enough messages in queue - wait if (Messages.Count > 100) continue; var result = consumer.Load(Topic, offsetByPartition, 300); var messageCount = 0; foreach (var tuple in result) { Messages.Enqueue(tuple); offsetByPartition[tuple.Item1] += Message.CalculateOnDiskMessageLength(tuple.Item2.Payload.Length); messageCount++; } // Wait for 500 msecond, if there is no new messages // This value should be configurable if (messageCount == 0) Thread.Sleep(500); } }); }