예제 #1
0
        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);
            });
        }
예제 #2
0
 public IObservable <TValue> GetChanges() => _dataStore.GetChanges <TValue>();
예제 #3
0
 public IObservable <T> GetChanges <T>() => _fast.GetChanges <T>().Merge(_slow.GetChanges <T>()).Distinct();