public async Task InstallProjectionFor <TProjection>() where TProjection : IEventStoreProjection
        {
            var matchingProjections = _projections.OfType <TProjection>().ToList();

            var projectionBuilder = new ProjectionBuilder();
            var projectionManager = _eventStoreConnectionString.CreateProjectionsManager();
            var credentials       = _eventStoreConnectionString.GetUserCredentials();

            foreach (var projection in matchingProjections)
            {
                var name  = $"project-to-{projection.ProjectionName}";
                var query = projectionBuilder.BuildStreamProjection(projection.GetInterestingStreams(), projection.ProjectionName);

                await projectionManager.CreateOrUpdateContinuousQueryAsync(name, query, credentials).ConfigureAwait(false);
            }
        }
Exemplo n.º 2
0
        public async Task InstallProjectionFor <TProcessManager>() where TProcessManager : IManageProcess
        {
            var matchingProcessManagers = _processManagers.OfType <TProcessManager>().ToList();

            var projectionBuilder = new ProjectionBuilder();
            var projectionManager = _eventStoreConnectionString.CreateProjectionsManager();
            var credentials       = _eventStoreConnectionString.GetUserCredentials();

            foreach (var processManager in matchingProcessManagers)
            {
                var name  = $"project-to-{processManager.ProcessName}";
                var query = projectionBuilder.BuildStreamProjection(processManager.GetStreamsToProcess(),
                                                                    processManager.ProcessName,
                                                                    processManager.GetEventMappings().Select(x => new ProjectionBuilder.EventMap(x.Key.Name, x.Value)));

                await projectionManager.CreateOrUpdateContinuousQueryAsync(name, query, credentials).ConfigureAwait(false);
            }
        }
Exemplo n.º 3
0
        public async Task InstallConsumerGroupFor(string stream, Func <PersistentSubscriptionSettingsBuilder, PersistentSubscriptionSettingsBuilder> alterSettings = null)
        {
            var settings = PersistentSubscriptionSettings.Create().PreferRoundRobin().ResolveLinkTos();

            alterSettings = alterSettings ?? (x => x);

            settings = alterSettings(settings);

            var subscriberSettings = _environment.GetSettings <SubscribersSettings>();
            var groupName          = subscriberSettings.GetPersistentSubscriptionGroupNameFor(stream, _environment);

            try
            {
                await _eventStoreConnection.CreatePersistentSubscriptionAsync(stream, groupName, settings, _eventStoreConnectionString.GetUserCredentials()).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                _environment.Log(ex, "Failed to create consumer group for stream: {0}", LogLevel.Error, stream);
            }
        }