예제 #1
0
        private void Init()
        {
            _maxDispatchedCheckpoint = 0;
            DumpProjections();

            TenantContext.Enter(_config.TenantId);

            _housekeeper.Init();

            _eventstore = Wireup
                          .Init()
                          .LogTo(t => new NEventStoreLog4NetLogger(LoggerFactory.Create(t)))
                          .UsingMongoPersistence(() => _config.EventStoreConnectionString, new DocumentObjectSerializer())
                          .InitializeStorageEngine()
                          .Build();

            ConfigureProjections();

            // cleanup
            _housekeeper.RemoveAll(_eventstore.Advanced);

            var allSlots = _projectionsBySlot.Keys.ToArray();

            var allClients = new List <ICommitPollingClient> ();

            //recreate all polling clients.
            foreach (var bucket in _config.BucketInfo)
            {
                var client = _pollingClientFactory.Create(_eventstore.Advanced, "bucket: " + String.Join(",", bucket.Slots));
                allClients.Add(client);
                _bucketToClient.Add(bucket, client);
            }

            _clients = allClients.ToArray();

            foreach (var slotName in allSlots)
            {
                MetricsHelper.CreateMeterForDispatcherCountSlot(slotName);
                var startCheckpoint = GetStartCheckpointForSlot(slotName);
                Logger.InfoFormat("Slot {0} starts from {1}", slotName, startCheckpoint);

                var name = slotName;
                //find right consumer
                var slotBucket = _config.BucketInfo.SingleOrDefault(b =>
                                                                    b.Slots.Any(s => s.Equals(slotName, StringComparison.OrdinalIgnoreCase))) ??
                                 _config.BucketInfo.Single(b => b.Slots[0] == "*");
                var client = _bucketToClient[slotBucket];
                client.AddConsumer(commit => DispatchCommit(commit, name, startCheckpoint));
            }

            MetricsHelper.SetProjectionEngineCurrentDispatchCount(() => _countOfConcurrentDispatchingCommit);
        }
        private async Task InitAsync()
        {
            _maxDispatchedCheckpoint = 0;
            DumpProjections();

            TenantContext.Enter(_config.TenantId);

            await _housekeeper.InitAsync().ConfigureAwait(false);

            await ConfigureProjectionsAsync().ConfigureAwait(false);

            // cleanup
            await _housekeeper.RemoveAllAsync(_persistence).ConfigureAwait(false);

            var allSlots = _projectionsBySlot.Keys.ToArray();

            var allClients = new List <ICommitPollingClient>();

            //recreate all polling clients.
            foreach (var bucket in _config.BucketInfo)
            {
                string pollerId = "bucket: " + String.Join(",", bucket.Slots);
                var    client   = _pollingClientFactory.Create(_persistence, pollerId);
                allClients.Add(client);
                _bucketToClient.Add(bucket, client);
                client.Configure(GetStartGlobalCheckpoint(bucket.Slots), 4000);
            }

            _clients = allClients.ToArray();

            foreach (var slotName in allSlots)
            {
                KernelMetricsHelper.CreateMeterForDispatcherCountSlot(slotName);
                var startCheckpoint = GetStartCheckpointForSlot(slotName);
                _logger.InfoFormat("Slot {0} starts from {1}", slotName, startCheckpoint);

                var name = slotName;
                //find right consumer
                var slotBucket = _config.BucketInfo.SingleOrDefault(b =>
                                                                    b.Slots.Any(s => s.Equals(slotName, StringComparison.OrdinalIgnoreCase))) ??
                                 _config.BucketInfo.Single(b => b.Slots[0] == "*");
                var client = _bucketToClient[slotBucket];
                client.AddConsumer($"SLOT: {slotName}", commit => DispatchCommitAsync(commit, name, startCheckpoint));
            }

            Initialized = true;
            KernelMetricsHelper.SetProjectionEngineCurrentDispatchCount(() => _countOfConcurrentDispatchingCommit);
        }
        public ProcessManagerDispatcher(
            ProcessManagerConfiguration configuration,
            IMongoDatabase supportDatabase,
            ICommitPollingClientFactory pollingClientFactory,
            IPersistence persistence,
            ICommandBus commandBus,
            IMessageBus messageBus)
        {
            _configuration        = configuration;
            _commandBus           = commandBus;
            _checkpointCollection = supportDatabase.GetCollection <ProcessManagerCheckpoint>("sysPmCheckpoints");
            _currentCheckpoint    = _checkpointCollection.FindOneById(ProcessManagerId)
                                    ?? new ProcessManagerCheckpoint()
            {
                Id = ProcessManagerId, LastDispatchedPosition = 0
            };
            Logger = NullLogger.Instance;

            _client = pollingClientFactory.Create(persistence, "ProcessManager");
            _client.AddConsumer("ProcessManager", Dispatch);
            _messageBus = messageBus;
        }