public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            services.AddSwaggerGen(x =>
            {
                x.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "Read Api Eventflow Demo - API", Version = "v1"
                });
            });

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);

            string           elasticSearchUrl = Environment.GetEnvironmentVariable("ELASTICSEARCHURL");
            ContainerBuilder containerBuilder = new ContainerBuilder();
            Uri node = new Uri(elasticSearchUrl);
            ConnectionSettings settings = new ConnectionSettings(node);

            settings.DisableDirectStreaming();

            ElasticClient elasticClient      = new ElasticClient(settings);
            string        rabbitMqConnection = Environment.GetEnvironmentVariable("RABBITMQCONNECTION");

            Options = EventFlowOptions.New
                      .UseAutofacContainerBuilder(containerBuilder)
                      .AddDefaults(typeof(Employee).Assembly)
                      .ConfigureElasticsearch(() => elasticClient)
                      .RegisterServices(sr => sr.Register <IScopedContext, ScopedContext>(Lifetime.Scoped))
                      .RegisterServices(sr => sr.RegisterType(typeof(EmployeeLocator)))
                      .UseElasticsearchReadModel <EmployeeReadModel, EmployeeLocator>()
                      .RegisterServices(sr => sr.RegisterType(typeof(TransactionLocator)))
                      .UseElasticsearchReadModel <TransactionReadModel, TransactionLocator>()
                      .AddQueryHandlers(typeof(ESTransactionGetQueryHandler), typeof(ESEmployeeGetQueryHandler))
                      .AddAsynchronousSubscriber <EmployeeAggregate, EmployeeId, EmployeeAddedEvent, AddNewEmployeeSubscriber>()
                      .AddSubscribers(typeof(AllEventsSubscriber))
                      .Configure(c => c.IsAsynchronousSubscribersEnabled = true)
                      .Configure(c => c.ThrowSubscriberExceptions        = true)
                      .SubscribeToRabbitMq(
                RabbitMqConfiguration.With(new Uri(rabbitMqConnection),
                                           true, 5, "eventflow"))

                      .AddAspNetCore();

            containerBuilder.Populate(services);
            var container = containerBuilder.Build();

            using (var scope = container.BeginLifetimeScope())
            {
                var subscriber           = scope.Resolve <IRabbitMqSubscriber>();
                var configuration        = scope.Resolve <IRabbitMqConfiguration>();
                var domainEventPublisher = scope.Resolve <IDomainEventPublisher>();
                subscriber.SubscribeAsync(configuration.Exchange, configuration.Exchange + "Queue", EventFlowOptionsRabbitMqExtensions.Listen,
                                          domainEventPublisher, cancellationToken: CancellationToken.None).Wait();
            }

            var _tenantIndex = new ElasticSearchIndex(elasticSearchUrl);

            _tenantIndex.CreateIndex("employeeindex", elasticSearchUrl);
            services.AddSingleton(_tenantIndex.ElasticClient);
            return(new AutofacServiceProvider(container));
        }
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            services.AddSwaggerGen(x =>
            {
                x.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "Eventflow Demo - API", Version = "v1"
                });
                x.OperationFilter <SwaggerAuthorizationHeaderParameterOperationFilter>();
            });

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
            ContainerBuilder containerBuilder   = new ContainerBuilder();
            string           rabbitMqConnection = Environment.GetEnvironmentVariable("RABBITMQCONNECTION");
            string           elasticSearchUrl   = Environment.GetEnvironmentVariable("ELASTICSEARCHURL");

            Uri node = new Uri(elasticSearchUrl);
            ConnectionSettings settings = new ConnectionSettings(node);
            var dataRetrieval           = new DataRetrieval()
            {
                Enabled = true
            };

            settings.DisableDirectStreaming();

            ElasticClient elasticClient = new ElasticClient(settings);

            EventFlowOptions.New
            .UseAutofacContainerBuilder(containerBuilder)
            .AddDefaults(typeof(Employee).Assembly)
            .ConfigureEventStore()
            .ConfigureElasticsearch(() => elasticClient)
            .PublishToRabbitMq(
                RabbitMqConfiguration.With(new Uri(rabbitMqConnection),
                                           true, 5, "eventflow"))
            .RegisterServices(sr => sr.Register <IScopedContext, ScopedContext>(Lifetime.Scoped))
            .RegisterServices(sr => sr.RegisterType(typeof(EmployeeLocator)))
            .UseElasticsearchReadModel <EmployeeReadModel, EmployeeLocator>()
            .RegisterServices(sr => sr.RegisterType(typeof(TransactionLocator)))
            .UseElasticsearchReadModel <TransactionReadModel, TransactionLocator>()
            .ConfigureDataRetrieval(dataRetrieval, typeof(EmployeeReadModel).Assembly)
            .AddAspNetCore();

            containerBuilder.Populate(services);
            var _tenantIndex = new ElasticSearchIndex(elasticSearchUrl);

            _tenantIndex.CreateIndex("employeeindex", elasticSearchUrl);
            services.AddSingleton(_tenantIndex.ElasticClient);
            return(new AutofacServiceProvider(containerBuilder.Build()));
        }
示例#3
0
        internal void Index(ElasticSearchIndex index)
        {
            var elasticClient = GetClient();


            var observableBulkAll = elasticClient.BulkAll(index.Documents, b => b
                                                          .Index(index.Name)
                                                          .Type("entry")
                                                          .BackOffRetries(5)
                                                          .BackOffTime("30s")
                                                          .RefreshOnCompleted(true)
                                                          .MaxDegreeOfParallelism(4)
                                                          .Size(30000)
                                                          );

            var bulkAllObserver = new BulkAllObserver(
                onError: (e) => { throw e; },
                onCompleted: () => DoSomething(index.Name),
                onNext: (b) => DoSomethingElse((BulkAllResponse)b, index.Name)
                );

            observableBulkAll.Subscribe(bulkAllObserver);
        }
示例#4
0
 public ElasticSearchIndexWithRecords(ElasticSearchIndex index)
 {
     IndexName          = index.IndexName;
     DocumentIdProperty = index.DocumentIdProperty;
     InsertOnlyMode     = index.InsertOnlyMode;
 }