diff --git a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostModule.cs b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostModule.cs index b827e4a2..b9534d5a 100644 --- a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostModule.cs +++ b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostModule.cs @@ -1,3 +1,4 @@ +using Hangfire.Redis; using Swagger; using Volo.Abp.BackgroundJobs.Hangfire; @@ -50,7 +51,7 @@ namespace Lion.AbpPro { app.UseMiniProfiler(); } - + app.UseRouting(); app.UseCors(AbpProHttpApiHostConst.DefaultCorsPolicyName); app.UseAuthentication(); @@ -91,11 +92,16 @@ namespace Lion.AbpPro private void ConfigureHangfire(ServiceConfigurationContext context) { + var redisStorageOptions = new RedisStorageOptions() + { + Db = context.Services.GetConfiguration().GetValue("Hangfire:Redis:DB") + }; + Configure(options => { options.IsJobExecutionEnabled = true; }); context.Services.AddHangfireServer(); context.Services.AddHangfire(config => { - config.UseRedisStorage(ConnectionMultiplexer.Connect(context.Services.GetConfiguration().GetConnectionString("Hangfire"))); + config.UseRedisStorage(ConnectionMultiplexer.Connect(context.Services.GetConfiguration().GetValue("Hangfire:Redis:Host")), redisStorageOptions); var delaysInSeconds = new[] { 10, 60, 60 * 3 }; // 重试时间间隔 const int Attempts = 3; // 重试次数 config.UseFilter(new AutomaticRetryAttribute() { Attempts = Attempts, DelaysInSeconds = delaysInSeconds }); @@ -113,14 +119,12 @@ namespace Lion.AbpPro { context.Services.AddMiniProfiler(options => options.RouteBasePath = "/profiler").AddEntityFramework(); } - } /// /// 配置JWT /// - private void ConfigureJwtAuthentication(ServiceConfigurationContext context, - IConfiguration configuration) + private void ConfigureJwtAuthentication(ServiceConfigurationContext context, IConfiguration configuration) { context.Services.AddAuthentication(options => { @@ -333,7 +337,7 @@ namespace Lion.AbpPro options.IgnoredUrls.Add("/cap"); }); } - + #endregion } } \ No newline at end of file diff --git a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/appsettings.json b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/appsettings.json index 2ae90032..320af979 100644 --- a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/appsettings.json +++ b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/appsettings.json @@ -35,7 +35,12 @@ }, "ConnectionStrings": { "Default": "Data Source=localhost;Port=3306;Database=LionAbpProDB;uid=root;pwd=1q2w3E*;charset=utf8mb4;Allow User Variables=true;AllowLoadLocalInfile=true", - "Hangfire": "localhost:6379,defaultdatabase=5" + }, + "Hangfire": { + "Redis": { + "Host": "localhost:6379", + "DB": "2" + } }, "Redis": { "Configuration": "localhost,password=1q2w3E*,defaultdatabase=1"