Exemplo n.º 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            RebusConfig rebusConfig = Configuration.GetValue <RebusConfig>("RabbitMq");

            services.AddControllers();

            services.AddMainServices();
            services.AddRebus(configure =>
                              configure.Logging(l => l.Console())
                              .Transport(t => t.UseRabbitMqAsOneWayClient($"amqp://{rebusConfig.Username}:{rebusConfig.Password}@{rebusConfig.Host}"))
                              .Options(o =>
            {
                o.SetMaxParallelism(1);
                o.SetNumberOfWorkers(1);
            }));

            services.AddDbContext <MasterDbContext>(options =>
                                                    options.UseMySQL(Configuration.GetConnectionString("MasterDB")));
            services.AddDbContext <SlaveDbContext>(options =>
                                                   options.UseMySQL(Configuration.GetConnectionString("Slave1DB")));
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting worker: " + WorkerId);

            var builder = new ConfigurationBuilder()
                          .SetBasePath(Path.Combine(AppContext.BaseDirectory))
                          .AddJsonFile("appsettings.json", optional: true);

            var configuration = builder.Build();

            RebusConfig rebusConfig = configuration.GetValue <RebusConfig>("RabbitMq");

            var serviceProvider = new ServiceCollection()
                                  .AddLogging()
                                  .AddRebus(configure =>
                                            configure.Logging(l => l.Console())//.Logging(l => l.Use(new MSLoggerFactoryAdapter(new LoggerFactory())))
                                            .Transport(t => t.UseRabbitMq($"amqp://{rebusConfig.Username}:{rebusConfig.Password}@{rebusConfig.Host}", rebusConfig.QueueName))
                                            .Routing(r => r.TypeBased().MapAssemblyOf <WorkTriggeredMessage>("test"))
                                            .Options(o =>
            {
                o.SetMaxParallelism(1);
                o.SetNumberOfWorkers(1);
            }))
                                  .AddDbContext <MasterDbContext>(options =>
                                                                  options.UseMySQL(configuration.GetConnectionString("MasterDB")))
                                  .AddDbContext <SlaveDbContext>(options =>
                                                                 options.UseMySQL(configuration.GetConnectionString("Slave1Db")))
                                  .AddScoped <IConfiguration>(c => configuration)
                                  .AddScoped <IHandleMessages <WorkTriggeredMessage>, WorkerManager>()
                                  .BuildServiceProvider();

            serviceProvider.UseRebus(bus =>
            {
                bus.Subscribe <WorkTriggeredMessage>().Wait();
            });

            Console.WriteLine(" Press [enter] to exit.");
            Console.ReadLine();
        }
Exemplo n.º 3
0
        public void ConfigureServices(IServiceCollection services)
        {
            var rebusConfig = new RebusConfig();

            Configuration.Bind("Rebus", rebusConfig);

            Debug.WriteLine(rebusConfig.RabbitMQConnection);

            services.AddControllersWithViews();

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "FinanceMonitor.Identity", Version = "v1"
                });
            });


            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            services.AddIdentity <ApplicationUser, IdentityRole>(x =>
            {
                x.Password.RequireDigit           = false;
                x.Password.RequiredLength         = 0;
                x.Password.RequireLowercase       = false;
                x.Password.RequireUppercase       = false;
                x.Password.RequireNonAlphanumeric = false;
            })
            .AddEntityFrameworkStores <ApplicationDbContext>()
            .AddDefaultTokenProviders();

            var builder = services.AddIdentityServer(options =>
            {
                options.Events.RaiseErrorEvents       = true;
                options.Events.RaiseInformationEvents = true;
                options.Events.RaiseFailureEvents     = true;
                options.Events.RaiseSuccessEvents     = true;

                // see https://identityserver4.readthedocs.io/en/latest/topics/resources.html
                options.EmitStaticAudienceClaim = true;
            })
                          .AddInMemoryIdentityResources(Config.IdentityResources)
                          .AddInMemoryApiScopes(Config.ApiScopes)
                          .AddInMemoryClients(Config.Clients)
                          .AddInMemoryApiResources(Config.ApiResources)
                          .AddAspNetIdentity <ApplicationUser>();

            // not recommended for production - you need to store your key material somewhere secure
            builder.AddDeveloperSigningCredential();

            services.AddAuthentication()
            .AddGoogle(options =>
            {
                options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;

                // register your IdentityServer with Google at https://console.developers.google.com
                // enable the Google+ API
                // set the redirect URI to https://localhost:5001/signin-google
                options.ClientId     = "copy client ID from Google here";
                options.ClientSecret = "copy client secret from Google here";
            });

            services.AddRebus(configure =>
            {
                configure.Transport(t => t.UseRabbitMq(rebusConfig.RabbitMQConnection, "identity")
                                    .ClientConnectionName("identity"));
                configure.Routing(r => r.TypeBased().MapAssemblyOf <Message>("api"));
                return(configure);
            });

            services.AddCors();

            AddCustomHealthCheck(services, Configuration);
        }
Exemplo n.º 4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // services.AddSingleton<Serilog.Core.Logger>(container => new LoggerConfiguration()
            //     //.ConfigureEnrichers(container)
            //     .ConfigureElk("http://elk:9200", Configuration.GetSection("Logging:Elk"), container)
            //     .ConfigureSelfLog(container)
            //     .CreateLogger());

            var rebusConfig = new RebusConfig();

            Configuration.Bind("Rebus", rebusConfig);

            services.Configure <StockOptions>(x =>
            {
                x.ConnectionString = Configuration.GetConnectionString("DefaultConnection");
            });

            services.AddScoped <IStockRepository, StockRepository>();
            services.AddScoped <IYahooApiService, YahooApiService>();
            services.AddScoped <IUserStockService, UserStockService>();
            services.AddScoped <IUserRepository, UserRepository>();
            services.AddScoped <IManagementRepository, ManagementRepository>();

            services.AddMediatR(typeof(Stock).GetTypeInfo().Assembly);

            services.AddControllers()
            .AddJsonOptions(opts => { opts.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); });

            ConfigureSwagger(services);

            ConfigureQuartz(services);

            SqlMapper.AddTypeMap(typeof(DateTime), DbType.DateTime2);

            services.AddCors();

            services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme)
            .AddJwtBearer(options =>
            {
                // base-address of your identityserver
                options.Authority = Configuration.GetSection("Identity")["Authority"];

                options.Audience = "api";

                options.TokenValidationParameters = new TokenValidationParameters()
                {
                    ValidateIssuer = false,
                };

                options.RequireHttpsMetadata = false;
            });

            services.AutoRegisterHandlersFromAssemblyOf <UserCreatedHandler>();
            services.AddRebus(configure =>
            {
                configure.Transport(t =>
                                    t.UseRabbitMq(rebusConfig.RabbitMQConnection, "api").ClientConnectionName("api"));
                configure.Routing(r => r.TypeBased().Map <SymbolHistoryChanged>("charts"));

                return(configure);
            });

            AddCustomHealthCheck(services, Configuration);
        }