Browse Source

fix: hangfire redis指定DB #79

pull/89/head
王军 3 years ago
parent
commit
658f2a36ad
  1. 16
      aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostModule.cs
  2. 7
      aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/appsettings.json

16
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<int>("Hangfire:Redis:DB")
};
Configure<AbpBackgroundJobOptions>(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<string>("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();
}
}
/// <summary>
/// 配置JWT
/// </summary>
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
}
}

7
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"

Loading…
Cancel
Save