Browse Source

Cap events and gateway enhancements

pull/132/head
cKey 5 years ago
parent
commit
53845609fc
  1. 10
      aspnet-core/LINGYUN.MicroService.ApiGateway.sln
  2. 8
      aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/DotNetCore/CAP/Processor/AbpCapExpiresMessageCleanupBackgroundWorker.cs
  3. 41
      aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN.Abp.EventBus.CAP.xml
  4. 30
      aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN/Abp/EventBus/CAP/AbpCAPEventBusModule.cs
  5. 10
      aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN/Abp/EventBus/CAP/AbpCAPEventBusOptions.cs
  6. 31
      aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN/Abp/EventBus/CAP/FailedThresholdCallbackNotifier.cs
  7. 9
      aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN/Abp/EventBus/CAP/IFailedThresholdCallbackNotifier.cs
  8. 33
      aspnet-core/services/apigateway/LINGYUN.ApiGateway.Host/ApiGatewayHostModule.cs
  9. 1
      aspnet-core/services/apigateway/LINGYUN.ApiGateway.Host/LINGYUN.ApiGateway.Host.csproj
  10. 2
      aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/ApiGatewayHttpApiHostModule.cs

10
aspnet-core/LINGYUN.MicroService.ApiGateway.sln

@ -27,6 +27,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.ApiGateway.HttpApi"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.ApiGateway.HttpApi.Client", "modules\apigateway\LINGYUN.ApiGateway.HttpApi.Client\LINGYUN.ApiGateway.HttpApi.Client.csproj", "{4757C7D9-6AE9-477D-9829-55D9906AC3E6}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "common", "common", "{D6629DD3-BA0F-44B5-A97F-3B992ECAB85D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.EventBus.CAP", "modules\common\LINGYUN.Abp.EventBus.CAP\LINGYUN.Abp.EventBus.CAP.csproj", "{1DA1835B-9EA4-4095-A8CF-10E2778206D3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -69,6 +73,10 @@ Global
{4757C7D9-6AE9-477D-9829-55D9906AC3E6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4757C7D9-6AE9-477D-9829-55D9906AC3E6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4757C7D9-6AE9-477D-9829-55D9906AC3E6}.Release|Any CPU.Build.0 = Release|Any CPU
{1DA1835B-9EA4-4095-A8CF-10E2778206D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1DA1835B-9EA4-4095-A8CF-10E2778206D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1DA1835B-9EA4-4095-A8CF-10E2778206D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1DA1835B-9EA4-4095-A8CF-10E2778206D3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -84,6 +92,8 @@ Global
{4D686265-3927-43F5-B9BF-8A013F8BC9E8} = {AD93DD04-989C-40BE-A3F4-25DABF290423}
{D890BEBE-563A-47ED-B767-2E80077B5D37} = {AD93DD04-989C-40BE-A3F4-25DABF290423}
{4757C7D9-6AE9-477D-9829-55D9906AC3E6} = {AD93DD04-989C-40BE-A3F4-25DABF290423}
{D6629DD3-BA0F-44B5-A97F-3B992ECAB85D} = {630FB448-8C5C-438F-930D-B0209407DE6A}
{1DA1835B-9EA4-4095-A8CF-10E2778206D3} = {D6629DD3-BA0F-44B5-A97F-3B992ECAB85D}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B327C65A-BD15-480D-825E-9D5A870C521A}

8
aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/DotNetCore/CAP/Processor/AbpCapExpiresMessageCleanupBackgroundWorker.cs

@ -18,7 +18,7 @@ namespace DotNetCore.CAP.Processor
/// <summary>
/// 过期消息清理配置
/// </summary>
protected MessageCleanupOptions Options { get; }
protected AbpCAPEventBusOptions Options { get; }
/// <summary>
/// Initializer
/// </summary>
@ -39,7 +39,7 @@ namespace DotNetCore.CAP.Processor
AbpTimer timer,
IDataStorage storage,
IStorageInitializer initializer,
IOptions<MessageCleanupOptions> options,
IOptions<AbpCAPEventBusOptions> options,
IServiceScopeFactory serviceScopeFactory)
: base(timer, serviceScopeFactory)
{
@ -47,7 +47,7 @@ namespace DotNetCore.CAP.Processor
Options = options.Value;
Initializer = initializer;
timer.Period = Options.Interval;
timer.Period = Options.CleanUpExpiresMessageInterval;
}
/// <summary>
@ -67,7 +67,7 @@ namespace DotNetCore.CAP.Processor
{
Logger.LogDebug($"Collecting expired data from table: {table}");
var time = DateTime.Now;
await Storage.DeleteExpiresAsync(table, time, Options.ItemBatch);
await Storage.DeleteExpiresAsync(table, time, Options.CleanUpExpiresMessageBatch);
}
}
}

41
aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN.Abp.EventBus.CAP.xml

@ -59,7 +59,7 @@
Storage
</summary>
</member>
<member name="M:DotNetCore.CAP.Processor.AbpCapExpiresMessageCleanupBackgroundWorker.#ctor(Volo.Abp.Threading.AbpTimer,DotNetCore.CAP.Persistence.IDataStorage,DotNetCore.CAP.Persistence.IStorageInitializer,Microsoft.Extensions.Options.IOptions{LINGYUN.Abp.EventBus.CAP.MessageCleanupOptions},Microsoft.Extensions.DependencyInjection.IServiceScopeFactory)">
<member name="M:DotNetCore.CAP.Processor.AbpCapExpiresMessageCleanupBackgroundWorker.#ctor(Volo.Abp.Threading.AbpTimer,DotNetCore.CAP.Persistence.IDataStorage,DotNetCore.CAP.Persistence.IStorageInitializer,Microsoft.Extensions.Options.IOptions{LINGYUN.Abp.EventBus.CAP.AbpCAPEventBusOptions},Microsoft.Extensions.DependencyInjection.IServiceScopeFactory)">
<summary>
创建过期消息清理任务
</summary>
@ -121,6 +121,28 @@
</summary>
<param name="context"></param>
</member>
<member name="T:LINGYUN.Abp.EventBus.CAP.AbpCAPEventBusOptions">
<summary>
过期消息清理配置项
</summary>
</member>
<member name="P:LINGYUN.Abp.EventBus.CAP.AbpCAPEventBusOptions.NotifyFailedCallback">
<summary>
发布消息处理失败通知
</summary>
</member>
<member name="P:LINGYUN.Abp.EventBus.CAP.AbpCAPEventBusOptions.CleanUpExpiresMessageBatch">
<summary>
批量清理数量
default: 1000
</summary>
</member>
<member name="P:LINGYUN.Abp.EventBus.CAP.AbpCAPEventBusOptions.CleanUpExpiresMessageInterval">
<summary>
执行间隔(ms)
default: 3600000 (1 hours)
</summary>
</member>
<member name="T:LINGYUN.Abp.EventBus.CAP.AbpCAPExecutionFailedException">
<summary>
AbpECAPExecutionFailedException
@ -277,23 +299,6 @@
<param name="eventType"></param>
<param name="factory"></param>
</member>
<member name="T:LINGYUN.Abp.EventBus.CAP.MessageCleanupOptions">
<summary>
过期消息清理配置项
</summary>
</member>
<member name="P:LINGYUN.Abp.EventBus.CAP.MessageCleanupOptions.ItemBatch">
<summary>
批量清理数量
default: 1000
</summary>
</member>
<member name="P:LINGYUN.Abp.EventBus.CAP.MessageCleanupOptions.Interval">
<summary>
执行间隔(ms)
default: 3600000 (1 hours)
</summary>
</member>
<member name="T:Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions">
<summary>
CAP ServiceCollectionExtensions

30
aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN/Abp/EventBus/CAP/AbpCAPEventBusModule.cs

@ -4,7 +4,6 @@ using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
using Volo.Abp.BackgroundWorkers;
using Volo.Abp.EventBus;
using Volo.Abp.ExceptionHandling;
using Volo.Abp.Modularity;
namespace LINGYUN.Abp.EventBus.CAP
@ -24,22 +23,27 @@ namespace LINGYUN.Abp.EventBus.CAP
public override void ConfigureServices(ServiceConfigurationContext context)
{
var configuration = context.Services.GetConfiguration();
Configure<AbpCAPEventBusOptions>(configuration.GetSection("CAP:Abp"));
context.Services.AddTransient<IFailedThresholdCallbackNotifier, FailedThresholdCallbackNotifier>();
context.Services.AddCAPEventBus(options =>
{
configuration.GetSection("CAP:EventBus").Bind(options);
context.Services.ExecutePreConfiguredActions(options);
//if (options.FailedThresholdCallback == null)
//{
// options.FailedThresholdCallback = async (failed) =>
// {
// var exceptionNotifier = failed.ServiceProvider.GetService<IExceptionNotifier>();
// if (exceptionNotifier != null)
// {
// // TODO: 作为异常处理?
// await exceptionNotifier.NotifyAsync(new AbpCAPExecutionFailedException(failed.MessageType, failed.Message));
// }
// };
//}
if (options.FailedThresholdCallback == null)
{
options.FailedThresholdCallback = async (failed) =>
{
var exceptionNotifier = failed.ServiceProvider.GetService<IFailedThresholdCallbackNotifier>();
if (exceptionNotifier != null)
{
// TODO: 作为异常处理?
await exceptionNotifier.NotifyAsync(new AbpCAPExecutionFailedException(failed.MessageType, failed.Message));
}
};
}
});
}

10
aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN/Abp/EventBus/CAP/MessageCleanupOptions.cs → aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN/Abp/EventBus/CAP/AbpCAPEventBusOptions.cs

@ -3,17 +3,21 @@
/// <summary>
/// 过期消息清理配置项
/// </summary>
public class MessageCleanupOptions
public class AbpCAPEventBusOptions
{
/// <summary>
/// 发布消息处理失败通知
/// </summary>
public bool NotifyFailedCallback { get; set; } = false;
/// <summary>
/// 批量清理数量
/// default: 1000
/// </summary>
public int ItemBatch { get; set; } = 1000;
public int CleanUpExpiresMessageBatch { get; set; } = 1000;
/// <summary>
/// 执行间隔(ms)
/// default: 3600000 (1 hours)
/// </summary>
public int Interval { get; set; } = 3600000;
public int CleanUpExpiresMessageInterval { get; set; } = 3600000;
}
}

31
aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN/Abp/EventBus/CAP/FailedThresholdCallbackNotifier.cs

@ -0,0 +1,31 @@
using Microsoft.Extensions.Options;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.ExceptionHandling;
namespace LINGYUN.Abp.EventBus.CAP
{
[DisableConventionalRegistration]
public class FailedThresholdCallbackNotifier : IFailedThresholdCallbackNotifier
{
protected AbpCAPEventBusOptions Options { get; }
protected IExceptionNotifier ExceptionNotifier { get; }
public FailedThresholdCallbackNotifier(
IOptions<AbpCAPEventBusOptions> options,
IExceptionNotifier exceptionNotifier)
{
Options = options.Value;
ExceptionNotifier = exceptionNotifier;
}
public virtual async Task NotifyAsync(AbpCAPExecutionFailedException exception)
{
// 通过额外的选项来控制是否发送消息处理失败的事件
if (Options.NotifyFailedCallback)
{
await ExceptionNotifier.NotifyAsync(exception);
}
}
}
}

9
aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN/Abp/EventBus/CAP/IFailedThresholdCallbackNotifier.cs

@ -0,0 +1,9 @@
using System.Threading.Tasks;
namespace LINGYUN.Abp.EventBus.CAP
{
public interface IFailedThresholdCallbackNotifier
{
Task NotifyAsync(AbpCAPExecutionFailedException exception);
}
}

33
aspnet-core/services/apigateway/LINGYUN.ApiGateway.Host/ApiGatewayHostModule.cs

@ -3,10 +3,14 @@ using LINGYUN.Abp.EventBus.CAP;
using LINGYUN.ApiGateway.Localization;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Extensions.Caching.StackExchangeRedis;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Ocelot.Configuration.Repository;
using Ocelot.DependencyInjection;
using Ocelot.Extenssions;
@ -138,12 +142,6 @@ namespace LINGYUN.ApiGateway
.AddVirtualJson("/Localization/Host");
});
Configure<IdentityModelHttpRequestMessageOptions>(options =>
{
// See https://github.com/abpframework/abp/pull/4564
options.ConfigureHttpRequestMessage = (requestMessage) => { };
});
var mvcBuilder = context.Services.AddMvc();
mvcBuilder.AddApplicationPart(typeof(ApiGatewayHostModule).Assembly);
@ -156,6 +154,29 @@ namespace LINGYUN.ApiGateway
});
});
if (!hostingEnvironment.IsDevelopment())
{
// Ssl证书
var sslOptions = configuration.GetSection("App:SslOptions");
if (sslOptions.Exists())
{
var fileName = sslOptions["FileName"];
var password = sslOptions["Password"];
Configure<KestrelServerOptions>(options =>
{
options.ConfigureEndpointDefaults(cfg =>
{
cfg.UseHttps(fileName, password);
});
});
}
var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]);
context.Services
.AddDataProtection()
.PersistKeysToStackExchangeRedis(redis, "ApiGatewayHost-Protection-Keys");
}
context.Services
.AddOcelot()
.AddPolly()

1
aspnet-core/services/apigateway/LINGYUN.ApiGateway.Host/LINGYUN.ApiGateway.Host.csproj

@ -14,6 +14,7 @@
<PackageReference Include="DotNetCore.CAP.Dashboard" Version="3.0.4" />
<PackageReference Include="DotNetCore.CAP.RabbitMQ" Version="3.0.4" />
<PackageReference Include="DotNetCore.CAP.Sqlite" Version="3.0.4.2" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="3.1.8" />
<PackageReference Include="Ocelot.Provider.Polly" Version="16.0.1" />
<PackageReference Include="Serilog.AspNetCore" Version="3.4.0" />
<PackageReference Include="Serilog.Enrichers.Assembly" Version="2.0.0" />

2
aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/ApiGatewayHttpApiHostModule.cs

@ -188,7 +188,7 @@ namespace LINGYUN.ApiGateway
var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]);
context.Services
.AddDataProtection()
.PersistKeysToStackExchangeRedis(redis, "ApiGateway-Protection-Keys");
.PersistKeysToStackExchangeRedis(redis, "ApiGatewayAdmin-Protection-Keys");
}
Configure<AbpAutoMapperOptions>(options =>

Loading…
Cancel
Save