Ejemplo n.º 1
0
        private static CqrsConfigurer GetCqrsConfigurer(IServiceCollection services)
        {
            ServiceDescriptor descriptor = services.FirstOrDefault(s => s.ServiceType == typeof(CqrsConfigurer));

            if (descriptor == null)
            {
                var configurer = new CqrsConfigurer(services);
                services.AddSingleton(configurer);

                return(configurer);
            }

            var cqrsConfigurer = (CqrsConfigurer)descriptor.ImplementationInstance;

            // IServiceCollection instance can change
            cqrsConfigurer.Services = services;

            return(cqrsConfigurer);
        }
        public static IServiceCollection AddServiceBus(this IServiceCollection services, Action <ICqrsConfigurer> configurerAction)
        {
            // Numero di richieste contemporaneamente gestite
            int w = Environment.ProcessorCount * 10;

            var configurer = new CqrsConfigurer(services);

            configurerAction(configurer);

            services.AddTransient <IncludePrincipalClaimsStep>();

            services.AddRebus((configure, provider) =>
            {
                configurer.Provider     = provider;
                string connectionString = provider.GetRequiredService <IConfiguration>().GetConnectionString("Rebus");
                //EnsureDatabaseCreated(connectionString);

                return(configure
                       .Serialization(s => s.UseNewtonsoftJson())
                       .Options(o =>
                {
                    o.EnableSynchronousRequestReply(replyMaxAgeSeconds: 30);
                    o.SetNumberOfWorkers(w);
                    o.SetMaxParallelism(w);
                    o.IncludePrincipalClaims(provider);
                    o.SetDueTimeoutsPollInteval(TimeSpan.FromSeconds(1));
                    o.SimpleRetryStrategy(maxDeliveryAttempts: 1, secondLevelRetriesEnabled: true);
                })
                       //.Sagas(s => s.StoreInSqlServer(connectionString, "Sagas", "SagasIndex"))
                       //.Timeouts(t => t.StoreInSqlServer(connectionString, "MessageTimeouts"))
                       .Subscriptions(t => t.StoreInSqlServer(connectionString, "Subscriptions"))
                       .Logging(l => l.Serilog())
                       .Transport(configurer.ApplyActions)
                       .Routing(configurer.ApplyActions));
            });

            services.AddSingleton <IHostedService, RebusHostedService>(r => new RebusHostedService(r, configurer));

            return(services);
        }
Ejemplo n.º 3
0
 public RebusHostedService(IServiceProvider serviceProvider, CqrsConfigurer cqrsConfigurer)
 {
     _serviceProvider = serviceProvider;
     _cqrsConfigurer  = cqrsConfigurer;
 }