public IMongoStorage <TModel, TKey> GetCollection <TModel, TKey>() where TModel : class, IReadModelEx <TKey>
        {
            string collectionName = CollectionNames.GetCollectionName <TModel>();
            var    cache          = _rebuildContext.GetCollection <TModel, TKey>(collectionName);

            return(new CachedMongoStorage <TModel, TKey>(
                       _db.GetCollection <TModel>(collectionName),
                       cache
                       ));
        }
        public async Task Verify_basic_get_for_readmodel_when_signature_change()
        {
            SimpleTestAtomicReadModel.FakeSignature = 1;
            var rm = new SimpleTestAtomicReadModel(new SampleAggregateId(2));
            await _collectionWrapper.UpsertAsync(rm).ConfigureAwait(false);

            var sut  = CreateSut();
            var name = CollectionNames.GetCollectionName(typeof(SimpleTestAtomicReadModel));

            Assert.That(sut.CountReadModelToUpdateByName(name, 2), Is.EqualTo(1));
        }
        protected void Init()
        {
            var url    = new MongoUrl(ConfigurationManager.ConnectionStrings["readmodel"].ConnectionString);
            var client = new MongoClient(url);

            _db         = client.GetDatabase(url.DatabaseName);
            _collection = _db.GetCollection <SimpleTestAtomicReadModel>(
                CollectionNames.GetCollectionName <SimpleTestAtomicReadModel>());
            _persistence = new InMemoryPersistence();
            _db.Drop();

            _identityManager     = new IdentityManager(new CounterService(_db));
            _mongoBsonCollection = _db.GetCollection <BsonDocument>(CollectionNames.GetCollectionName <SimpleTestAtomicReadModel>());
        }
        public void OneTimeSetup()
        {
            var url    = new MongoUrl(ConfigurationManager.ConnectionStrings["readmodel"].ConnectionString);
            var client = new MongoClient(url);

            _db = client.GetDatabase(url.DatabaseName);
            _db.Drop();

            _collection = _db.GetCollection <SimpleTestAtomicReadModel>(
                CollectionNames.GetCollectionName <SimpleTestAtomicReadModel>());

            _persistence       = new InMemoryPersistence();
            _collectionWrapper = new AtomicMongoCollectionWrapper <SimpleTestAtomicReadModel>(
                _db,
                new AtomicReadModelFactory(),
                new LiveAtomicReadModelProcessor(new AtomicReadModelFactory(), new CommitEnhancer(), _persistence));
        }
 public void Start()
 {
     Metric.Gauge("checkpoint-behind-AtomicReadModels", CheckAllAtomicsValue(), Unit.Items);
     HealthChecks.RegisterHealthCheck("Slot-All-AtomicReadmodels", CheckSlotHealth());
     foreach (var readModelType in _atomicProjectionCheckpointManager.GetAllRegisteredAtomicReadModels())
     {
         var name = CollectionNames.GetCollectionName(readModelType);
         //try to create an instance to grab the version
         try
         {
             var readmodelVersion = _readModelFactory.GetReamdodelVersion(readModelType);
             Metric.Gauge("versions-behind-" + name, () => _versionLoader.CountReadModelToUpdateByName(name, readmodelVersion), Unit.Items);
         }
         catch (Exception ex)
         {
             Logger.ErrorFormat(ex, "Unable to setup metric for atomic readmodel {0}", readModelType.FullName);
         }
     }
 }
        public AtomicMongoCollectionWrapper(
            IMongoDatabase readmodelDb,
            IAtomicReadModelFactory atomicReadModelFactory,
            ILiveAtomicReadModelProcessor liveAtomicReadModelProcessor)
        {
            _liveAtomicReadModelProcessor = liveAtomicReadModelProcessor;

            var collectionName = CollectionNames.GetCollectionName <TModel>();

            _collection = readmodelDb.GetCollection <TModel>(collectionName);

            Logger = NullLogger.Instance;

            //Auto create the basic index you need
            _collection.Indexes.CreateOne(
                new CreateIndexModel <TModel>(
                    Builders <TModel> .IndexKeys
                    .Ascending(_ => _.ProjectedPosition),
                    new CreateIndexOptions()
            {
                Name       = "ProjectedPosition",
                Background = false
            }
                    )
                );

            _collection.Indexes.CreateOne(
                new CreateIndexModel <TModel>(
                    Builders <TModel> .IndexKeys
                    .Ascending(_ => _.ReadModelVersion),
                    new CreateIndexOptions()
            {
                Name       = "ReadModelVersion",
                Background = false
            }
                    )
                );

            _actualVersion = atomicReadModelFactory.GetReamdodelVersion(typeof(TModel));
        }
Esempio n. 7
0
 protected IMongoCollection <T> GetCollection <T>()
     where T : IAtomicReadModel
 {
     return(_db.GetCollection <T>(CollectionNames.GetCollectionName <T>()));
 }
Esempio n. 8
0
 public DocumentWriter(IMongoDatabase readModelDb)
 {
     _collection = readModelDb.GetCollection <DocumentReadModel>(CollectionNames.GetCollectionName <DocumentReadModel>());
 }