public KafkaBackedDb(IChangeTrackingDataStore dataStore, KafkaConsumer <TValue> kafkaConsumer) { _dataStore = dataStore; _dataStore.GetChanges <Offset>().Subscribe(offset => Console.WriteLine(offset)); var offsetKey = $"{typeof(TValue).Name}.offset"; var currentOffset = _dataStore.Get <long>(offsetKey).Result; kafkaConsumer.SeekToOffset(currentOffset); kafkaConsumer.Start(); kafkaConsumer.Subscription .ObserveOn(TaskPoolScheduler.Default) .SubscribeOn(TaskPoolScheduler.Default) .Subscribe(async message => { var value = message.Value; var currentValue = await _dataStore.Get <TValue>(message.Key); if (!(currentValue is null)) { value.UpdateObject(currentValue); } await _dataStore.Set(value, message.Key); await _dataStore.Set(message.Offset.Value, offsetKey); }); }
public IObservable <TValue> GetChanges() => _dataStore.GetChanges <TValue>();
public IObservable <T> GetChanges <T>() => _fast.GetChanges <T>().Merge(_slow.GetChanges <T>()).Distinct();