Esempio n. 1
0
        public ChangeFeedService(
            CosmosDBStreamConfigurator configurator,
            IServiceProvider serviceProvider,
            IGrainIdentity id,
            IOptions <SiloOptions> siloOptions,
            Silo silo,
            ILoggerFactory loggerFactory)
            : base(id, silo, loggerFactory)
        {
            this._logger = loggerFactory.CreateLogger <ChangeFeedService>();

            var processor = new List <IProcessor>();

            foreach (var setting in configurator.Settings)
            {
                processor.Add(ChangeFeedProcessor.Create(
                                  setting.Key,
                                  siloOptions.Value.SiloName,
                                  setting.Value.Options,
                                  serviceProvider,
                                  TaskScheduler.Current,
                                  (IStreamMapper)ActivatorUtilities.CreateInstance(serviceProvider, setting.Value.MapperType)
                                  ));
            }

            this._processors = processor;
        }
        /// <summary>
        /// Register CosmosDB Change feed stream provider to Orleans runtime.
        /// </summary>
        /// <param name="configure">Configuration builder delegate</param>
        public static ISiloBuilder AddCosmosDBStreaming(this ISiloBuilder siloBuilder, Action <CosmosDBStreamConfigurator> configure)
        {
            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            var configurator = new CosmosDBStreamConfigurator();

            configure.Invoke(configurator);

            foreach (var config in configurator.Settings)
            {
                siloBuilder.AddSimpleMessageStreamProvider(config.Key);
            }

            return(siloBuilder
                   .Configure(configure)
                   .AddGrainService <ChangeFeedService>()
                   .ConfigureServices(services => services.AddSingleton <CosmosDBStreamConfigurator>(configurator))
                   .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(ChangeFeedService).Assembly).WithReferences()));
        }