示例#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);
            });
        }
 public LayeredDataStore(IChangeTrackingDataStore fast, IChangeTrackingDataStore slow)
 {
     _fast = fast;
     _slow = slow;
 }