public async Task StartAsync(CancellationToken cancellationToken) { _consumer.Start(cancellationToken); await _consumer.Subscription.ForEachAsync(message => { Console.WriteLine($"[{message.Topic}:({message.Partition.Value}, {message.Offset.Value})]: {message.Message.Value}"); _consumer.Commit(message.Partition, message.Offset); }, cancellationToken); }
public KafkaBackedDb(RocksStore rocksStore, KafkaConsumer <TValue> kafkaConsumer) { _rocksStore = rocksStore; kafkaConsumer.Start(); kafkaConsumer.Subscription .ObserveOn(TaskPoolScheduler.Default) .SubscribeOn(TaskPoolScheduler.Default) .Subscribe(m => { var value = m.Value; var currentValue = _rocksStore.Get <string, TValue>(m.Key); if (!(currentValue is null)) { value.UpdateObject(currentValue); } _rocksStore.Add(m.Key, value); kafkaConsumer.Commit(m.Partition, m.Offset); }); }