Browse Source

remove custom CAP clean-up message backgroundwork

pull/439/head
cKey 4 years ago
parent
commit
08eafb1637
  1. 74
      aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/DotNetCore/CAP/Processor/AbpCapExpiresMessageCleanupBackgroundWorker.cs
  2. 119
      aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/DotNetCore/CAP/Processor/AbpCapProcessingServer.cs
  3. 27
      aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN.Abp.EventBus.CAP.csproj
  4. 105
      aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN.Abp.EventBus.CAP.xml
  5. 12
      aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN/Abp/EventBus/CAP/AbpCAPConsumerServiceSelector.cs
  6. 26
      aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN/Abp/EventBus/CAP/AbpCAPEventBusModule.cs
  7. 10
      aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN/Abp/EventBus/CAP/AbpCAPEventBusOptions.cs
  8. 119
      aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN/Abp/EventBus/CAP/CAPDistributedEventBus.cs
  9. 13
      aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/Microsoft/Extensions/DependencyInjection/ServiceCollectionExtensions.cs
  10. 3
      aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/appsettings.Development.json
  11. 3
      aspnet-core/services/LY.MicroService.LocalizationManagement.HttpApi.Host/appsettings.Development.json
  12. 3
      aspnet-core/services/LY.MicroService.PlatformManagement.HttpApi.Host/appsettings.Development.json
  13. 3
      aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/appsettings.Development.json
  14. 3
      aspnet-core/services/LY.MicroService.identityServer.HttpApi.Host/FodyWeavers.xml
  15. 3
      aspnet-core/services/LY.MicroService.identityServer.HttpApi.Host/appsettings.Development.json
  16. 3
      aspnet-core/services/LY.MicroService.identityServer/appsettings.Development.json

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

@ -1,74 +0,0 @@
using DotNetCore.CAP.Persistence;
using LINGYUN.Abp.EventBus.CAP;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System;
using System.Threading.Tasks;
using Volo.Abp.BackgroundWorkers;
using Volo.Abp.Threading;
namespace DotNetCore.CAP.Processor
{
/// <summary>
/// 过期消息清理任务
/// </summary>
public class AbpCapExpiresMessageCleanupBackgroundWorker : AsyncPeriodicBackgroundWorkerBase
{
/// <summary>
/// 过期消息清理配置
/// </summary>
protected AbpCAPEventBusOptions Options { get; }
/// <summary>
/// Initializer
/// </summary>
protected IStorageInitializer Initializer { get; }
/// <summary>
/// Storage
/// </summary>
protected IDataStorage Storage{ get; }
/// <summary>
/// 创建过期消息清理任务
/// </summary>
/// <param name="timer"></param>
/// <param name="storage"></param>
/// <param name="initializer"></param>
/// <param name="options"></param>
/// <param name="serviceScopeFactory"></param>
public AbpCapExpiresMessageCleanupBackgroundWorker(
AbpAsyncTimer timer,
IDataStorage storage,
IStorageInitializer initializer,
IOptions<AbpCAPEventBusOptions> options,
IServiceScopeFactory serviceScopeFactory)
: base(timer, serviceScopeFactory)
{
Storage = storage;
Options = options.Value;
Initializer = initializer;
timer.Period = Options.CleanUpExpiresMessageInterval;
}
/// <summary>
/// 异步执行任务
/// </summary>
/// <param name="workerContext"></param>
/// <returns></returns>
protected override async Task DoWorkAsync(PeriodicBackgroundWorkerContext workerContext)
{
var tables = new[]
{
Initializer.GetPublishedTableName(),
Initializer.GetReceivedTableName()
};
foreach (var table in tables)
{
Logger.LogDebug($"Collecting expired data from table: {table}");
var time = DateTime.Now;
await Storage.DeleteExpiresAsync(table, time, Options.CleanUpExpiresMessageBatch);
}
}
}
}

119
aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/DotNetCore/CAP/Processor/AbpCapProcessingServer.cs

@ -1,119 +0,0 @@
using DotNetCore.CAP.Internal;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace DotNetCore.CAP.Processor
{
/// <summary>
/// CapProcessingServer
/// </summary>
public class AbpCapProcessingServer : IProcessingServer
{
private readonly CancellationTokenSource _cts;
private readonly ILogger _logger;
private readonly ILoggerFactory _loggerFactory;
private readonly IServiceProvider _provider;
private Task _compositeTask;
private ProcessingContext _context;
private bool _disposed;
/// <summary>
/// CapProcessingServer
/// </summary>
/// <param name="logger"></param>
/// <param name="loggerFactory"></param>
/// <param name="provider"></param>
public AbpCapProcessingServer(
ILogger<AbpCapProcessingServer> logger,
ILoggerFactory loggerFactory,
IServiceProvider provider)
{
_logger = logger;
_loggerFactory = loggerFactory;
_provider = provider;
_cts = new CancellationTokenSource();
}
/// <summary>
/// Start
/// </summary>
public void Start(CancellationToken stoppingToken)
{
_logger.LogInformation("Starting the processing server.");
stoppingToken.Register(() =>
{
_cts.Cancel();
});
_context = new ProcessingContext(_provider, _cts.Token);
var processorTasks = GetProcessors()
.Select(InfiniteRetry)
.Select(p => p.ProcessAsync(_context));
_compositeTask = Task.WhenAll(processorTasks);
}
/// <summary>
/// Pulse
/// </summary>
public void Pulse()
{
_logger.LogTrace("Pulsing the processor.");
}
/// <summary>
/// Dispose
/// </summary>
public void Dispose()
{
if (_disposed)
{
return;
}
try
{
_disposed = true;
_logger.LogInformation("Shutting down the processing server...");
_cts.Cancel();
_compositeTask?.Wait((int)TimeSpan.FromSeconds(10).TotalMilliseconds);
}
catch (AggregateException ex)
{
var innerEx = ex.InnerExceptions[0];
if (!(innerEx is OperationCanceledException))
{
_logger.LogWarning(innerEx, $"Expected an OperationCanceledException, but found '{innerEx.Message}'.");
}
}
catch (Exception ex)
{
_logger.LogWarning(ex, "An exception was occured when disposing.");
}
finally
{
_logger.LogInformation("### CAP shutdown!");
}
}
private IProcessor InfiniteRetry(IProcessor inner)
{
return new InfiniteRetryProcessor(inner, _loggerFactory);
}
private IProcessor[] GetProcessors()
{
var returnedProcessors = new List<IProcessor>
{
_provider.GetRequiredService<TransportCheckProcessor>(),
_provider.GetRequiredService<MessageNeedToRetryProcessor>(),
};
return returnedProcessors.ToArray();
}
}
}

27
aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN.Abp.EventBus.CAP.csproj

@ -1,21 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\configureawait.props" />
<Import Project="..\..\..\common.props" />
<Import Project="..\..\..\common.props" />
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<RootNamespace />
<Description>Cap分布式事件总线</Description>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<DocumentationFile>$(SolutionDir)modules\common\LINGYUN.Abp.EventBus.CAP\LINGYUN.Abp.EventBus.CAP.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<RootNamespace />
<Description>Cap分布式事件总线</Description>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<DocumentationFile>$(SolutionDir)modules\common\LINGYUN.Abp.EventBus.CAP\LINGYUN.Abp.EventBus.CAP.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DotNetCore.CAP" Version="$(DotNetCoreCAPPackageVersion)" />
<PackageReference Include="Volo.Abp.BackgroundWorkers" Version="$(VoloAbpPackageVersion)" />
<PackageReference Include="Volo.Abp.EventBus" Version="$(VoloAbpPackageVersion)" />
<PackageReference Include="Volo.Abp.Json" Version="$(VoloAbpPackageVersion)" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="DotNetCore.CAP" Version="$(DotNetCoreCAPPackageVersion)" />
<PackageReference Include="Volo.Abp.EventBus" Version="$(VoloAbpPackageVersion)" />
<PackageReference Include="Volo.Abp.Json" Version="$(VoloAbpPackageVersion)" />
</ItemGroup>
</Project>

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

@ -4,39 +4,39 @@
<name>LINGYUN.Abp.EventBus.CAP</name>
</assembly>
<members>
<member name="T:DotNetCore.CAP.ConsumerServiceSelector">
<member name="T:LINGYUN.Abp.EventBus.CAP.AbpCAPConsumerServiceSelector">
<summary>
消费者查找器
</summary>
</member>
<member name="P:DotNetCore.CAP.ConsumerServiceSelector.CapOptions">
<member name="P:LINGYUN.Abp.EventBus.CAP.AbpCAPConsumerServiceSelector.CapOptions">
<summary>
CAP配置
</summary>
</member>
<member name="P:DotNetCore.CAP.ConsumerServiceSelector.AbpDistributedEventBusOptions">
<member name="P:LINGYUN.Abp.EventBus.CAP.AbpCAPConsumerServiceSelector.AbpDistributedEventBusOptions">
<summary>
Abp分布式事件配置
</summary>
</member>
<member name="P:DotNetCore.CAP.ConsumerServiceSelector.ServiceProvider">
<member name="P:LINGYUN.Abp.EventBus.CAP.AbpCAPConsumerServiceSelector.ServiceProvider">
<summary>
服务提供者
</summary>
</member>
<member name="M:DotNetCore.CAP.ConsumerServiceSelector.#ctor(System.IServiceProvider,Microsoft.Extensions.Options.IOptions{DotNetCore.CAP.CapOptions},Microsoft.Extensions.Options.IOptions{Volo.Abp.EventBus.Distributed.AbpDistributedEventBusOptions})">
<member name="M:LINGYUN.Abp.EventBus.CAP.AbpCAPConsumerServiceSelector.#ctor(System.IServiceProvider,Microsoft.Extensions.Options.IOptions{DotNetCore.CAP.CapOptions},Microsoft.Extensions.Options.IOptions{Volo.Abp.EventBus.Distributed.AbpDistributedEventBusOptions})">
<summary>
Creates a new <see cref="T:DotNetCore.CAP.Internal.ConsumerServiceSelector" />.
</summary>
</member>
<member name="M:DotNetCore.CAP.ConsumerServiceSelector.FindConsumersFromInterfaceTypes(System.IServiceProvider)">
<member name="M:LINGYUN.Abp.EventBus.CAP.AbpCAPConsumerServiceSelector.FindConsumersFromInterfaceTypes(System.IServiceProvider)">
<summary>
查找消费者集合
</summary>
<param name="provider"></param>
<returns></returns>
</member>
<member name="M:DotNetCore.CAP.ConsumerServiceSelector.GetHandlerDescription(System.Type,System.Type)">
<member name="M:LINGYUN.Abp.EventBus.CAP.AbpCAPConsumerServiceSelector.GetHandlerDescription(System.Type,System.Type)">
<summary>
获取事件处理器集合
</summary>
@ -44,71 +44,6 @@
<param name="typeInfo"></param>
<returns></returns>
</member>
<member name="T:DotNetCore.CAP.Processor.AbpCapExpiresMessageCleanupBackgroundWorker">
<summary>
过期消息清理任务
</summary>
</member>
<member name="P:DotNetCore.CAP.Processor.AbpCapExpiresMessageCleanupBackgroundWorker.Options">
<summary>
过期消息清理配置
</summary>
</member>
<member name="P:DotNetCore.CAP.Processor.AbpCapExpiresMessageCleanupBackgroundWorker.Initializer">
<summary>
Initializer
</summary>
</member>
<member name="P:DotNetCore.CAP.Processor.AbpCapExpiresMessageCleanupBackgroundWorker.Storage">
<summary>
Storage
</summary>
</member>
<member name="M:DotNetCore.CAP.Processor.AbpCapExpiresMessageCleanupBackgroundWorker.#ctor(Volo.Abp.Threading.AbpAsyncTimer,DotNetCore.CAP.Persistence.IDataStorage,DotNetCore.CAP.Persistence.IStorageInitializer,Microsoft.Extensions.Options.IOptions{LINGYUN.Abp.EventBus.CAP.AbpCAPEventBusOptions},Microsoft.Extensions.DependencyInjection.IServiceScopeFactory)">
<summary>
创建过期消息清理任务
</summary>
<param name="timer"></param>
<param name="storage"></param>
<param name="initializer"></param>
<param name="options"></param>
<param name="serviceScopeFactory"></param>
</member>
<member name="M:DotNetCore.CAP.Processor.AbpCapExpiresMessageCleanupBackgroundWorker.DoWorkAsync(Volo.Abp.BackgroundWorkers.PeriodicBackgroundWorkerContext)">
<summary>
异步执行任务
</summary>
<param name="workerContext"></param>
<returns></returns>
</member>
<member name="T:DotNetCore.CAP.Processor.AbpCapProcessingServer">
<summary>
CapProcessingServer
</summary>
</member>
<member name="M:DotNetCore.CAP.Processor.AbpCapProcessingServer.#ctor(Microsoft.Extensions.Logging.ILogger{DotNetCore.CAP.Processor.AbpCapProcessingServer},Microsoft.Extensions.Logging.ILoggerFactory,System.IServiceProvider)">
<summary>
CapProcessingServer
</summary>
<param name="logger"></param>
<param name="loggerFactory"></param>
<param name="provider"></param>
</member>
<member name="M:DotNetCore.CAP.Processor.AbpCapProcessingServer.Start(System.Threading.CancellationToken)">
<summary>
Start
</summary>
</member>
<member name="M:DotNetCore.CAP.Processor.AbpCapProcessingServer.Pulse">
<summary>
Pulse
</summary>
</member>
<member name="M:DotNetCore.CAP.Processor.AbpCapProcessingServer.Dispose">
<summary>
Dispose
</summary>
</member>
<member name="T:LINGYUN.Abp.EventBus.CAP.AbpCAPEventBusModule">
<summary>
AbpCAPEventBusModule
@ -120,12 +55,6 @@
</summary>
<param name="context"></param>
</member>
<member name="M:LINGYUN.Abp.EventBus.CAP.AbpCAPEventBusModule.OnApplicationInitialization(Volo.Abp.ApplicationInitializationContext)">
<summary>
OnApplicationInitialization
</summary>
<param name="context"></param>
</member>
<member name="T:LINGYUN.Abp.EventBus.CAP.AbpCAPEventBusOptions">
<summary>
过期消息清理配置项
@ -137,18 +66,6 @@
default: false
</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
@ -282,12 +199,17 @@
当前客户端
</summary>
</member>
<member name="P:LINGYUN.Abp.EventBus.CAP.CAPDistributedEventBus.JsonSerializer">
<summary>
typeof <see cref="T:Volo.Abp.Json.IJsonSerializer"/>
</summary>
</member>
<member name="P:LINGYUN.Abp.EventBus.CAP.CAPDistributedEventBus.CancellationTokenProvider">
<summary>
取消令牌
</summary>
</member>
<member name="M:LINGYUN.Abp.EventBus.CAP.CAPDistributedEventBus.#ctor(Microsoft.Extensions.DependencyInjection.IServiceScopeFactory,Microsoft.Extensions.Options.IOptions{Volo.Abp.EventBus.Distributed.AbpDistributedEventBusOptions},DotNetCore.CAP.ICapPublisher,Volo.Abp.Users.ICurrentUser,Volo.Abp.Clients.ICurrentClient,Volo.Abp.MultiTenancy.ICurrentTenant,Volo.Abp.Uow.IUnitOfWorkManager,Volo.Abp.Guids.IGuidGenerator,Volo.Abp.Timing.IClock,Volo.Abp.Threading.ICancellationTokenProvider,LINGYUN.Abp.EventBus.CAP.ICustomDistributedEventSubscriber)">
<member name="M:LINGYUN.Abp.EventBus.CAP.CAPDistributedEventBus.#ctor(Microsoft.Extensions.DependencyInjection.IServiceScopeFactory,Microsoft.Extensions.Options.IOptions{Volo.Abp.EventBus.Distributed.AbpDistributedEventBusOptions},DotNetCore.CAP.ICapPublisher,Volo.Abp.Users.ICurrentUser,Volo.Abp.Clients.ICurrentClient,Volo.Abp.MultiTenancy.ICurrentTenant,Volo.Abp.Json.IJsonSerializer,Volo.Abp.Uow.IUnitOfWorkManager,Volo.Abp.Guids.IGuidGenerator,Volo.Abp.Timing.IClock,Volo.Abp.Threading.ICancellationTokenProvider,LINGYUN.Abp.EventBus.CAP.ICustomDistributedEventSubscriber)">
<summary>
constructor
</summary>
@ -297,6 +219,7 @@
<param name="currentUser"></param>
<param name="currentClient"></param>
<param name="currentTenant"></param>
<param name="jsonSerializer"></param>
<param name="unitOfWorkManager"></param>
<param name="cancellationTokenProvider"></param>
<param name="guidGenerator"></param>

12
aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/DotNetCore/CAP/ConsumerServiceSelector.cs → aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN/Abp/EventBus/CAP/AbpCAPConsumerServiceSelector.cs

@ -1,5 +1,5 @@
using DotNetCore.CAP.Internal;
using LINGYUN.Abp.EventBus.CAP;
using DotNetCore.CAP;
using DotNetCore.CAP.Internal;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using System;
@ -10,15 +10,15 @@ using Volo.Abp.DependencyInjection;
using Volo.Abp.EventBus;
using Volo.Abp.EventBus.Distributed;
namespace DotNetCore.CAP
namespace LINGYUN.Abp.EventBus.CAP
{
/// <summary>
/// 消费者查找器
/// </summary>
[Dependency(ServiceLifetime.Singleton, ReplaceServices = true)]
[ExposeServices(typeof(IConsumerServiceSelector), typeof(ConsumerServiceSelector))]
[ExposeServices(typeof(IConsumerServiceSelector), typeof(AbpCAPConsumerServiceSelector))]
public class ConsumerServiceSelector : Internal.ConsumerServiceSelector
public class AbpCAPConsumerServiceSelector : ConsumerServiceSelector
{
/// <summary>
/// CAP配置
@ -36,7 +36,7 @@ namespace DotNetCore.CAP
/// <summary>
/// Creates a new <see cref="T:DotNetCore.CAP.Internal.ConsumerServiceSelector" />.
/// </summary>
public ConsumerServiceSelector(
public AbpCAPConsumerServiceSelector(
IServiceProvider serviceProvider,
IOptions<CapOptions> capOptions,
IOptions<AbpDistributedEventBusOptions> distributedEventBusOptions) : base(serviceProvider)

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

@ -1,8 +1,5 @@
using DotNetCore.CAP.Processor;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
using Volo.Abp.BackgroundWorkers;
using Volo.Abp.EventBus;
using Volo.Abp.Modularity;
@ -11,9 +8,7 @@ namespace LINGYUN.Abp.EventBus.CAP
/// <summary>
/// AbpCAPEventBusModule
/// </summary>
[DependsOn(
typeof(AbpEventBusModule),
typeof(AbpBackgroundWorkersModule))]
[DependsOn(typeof(AbpEventBusModule))]
public class AbpCAPEventBusModule : AbpModule
{
/// <summary>
@ -30,6 +25,9 @@ namespace LINGYUN.Abp.EventBus.CAP
context.Services.AddCAPEventBus(options =>
{
// 取消默认的五分钟高频清理
// options.CollectorCleaningInterval = 360_0000;
configuration.GetSection("CAP:EventBus").Bind(options);
context.Services.ExecutePreConfiguredActions(options);
if (options.FailedThresholdCallback == null)
@ -46,19 +44,5 @@ namespace LINGYUN.Abp.EventBus.CAP
}
});
}
/// <summary>
/// OnApplicationInitialization
/// </summary>
/// <param name="context"></param>
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
context.ServiceProvider
.GetRequiredService<IBackgroundWorkerManager>()
.Add(
context.ServiceProvider
.GetRequiredService<AbpCapExpiresMessageCleanupBackgroundWorker>()
);
}
}
}

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

@ -10,15 +10,5 @@
/// default: false
/// </summary>
public bool NotifyFailedCallback { get; set; } = false;
/// <summary>
/// 批量清理数量
/// default: 1000
/// </summary>
public int CleanUpExpiresMessageBatch { get; set; } = 1000;
/// <summary>
/// 执行间隔(ms)
/// default: 3600000 (1 hours)
/// </summary>
public int CleanUpExpiresMessageInterval { get; set; } = 360_0000;
}
}

119
aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LINGYUN/Abp/EventBus/CAP/CAPDistributedEventBus.cs

@ -5,6 +5,7 @@ using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Clients;
@ -12,6 +13,7 @@ using Volo.Abp.DependencyInjection;
using Volo.Abp.EventBus;
using Volo.Abp.EventBus.Distributed;
using Volo.Abp.Guids;
using Volo.Abp.Json;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Threading;
using Volo.Abp.Timing;
@ -51,10 +53,14 @@ namespace LINGYUN.Abp.EventBus.CAP
/// 当前客户端
/// </summary>
protected ICurrentClient CurrentClient { get; }
/// <summary>
/// 取消令牌
/// </summary>
protected ICancellationTokenProvider CancellationTokenProvider { get; }
/// <summary>
/// typeof <see cref="IJsonSerializer"/>
/// </summary>
protected IJsonSerializer JsonSerializer { get; }
/// <summary>
/// 取消令牌
/// </summary>
protected ICancellationTokenProvider CancellationTokenProvider { get; }
/// <summary>
/// constructor
/// </summary>
@ -64,6 +70,7 @@ namespace LINGYUN.Abp.EventBus.CAP
/// <param name="currentUser"></param>
/// <param name="currentClient"></param>
/// <param name="currentTenant"></param>
/// <param name="jsonSerializer"></param>
/// <param name="unitOfWorkManager"></param>
/// <param name="cancellationTokenProvider"></param>
/// <param name="guidGenerator"></param>
@ -75,6 +82,7 @@ namespace LINGYUN.Abp.EventBus.CAP
ICurrentUser currentUser,
ICurrentClient currentClient,
ICurrentTenant currentTenant,
IJsonSerializer jsonSerializer,
IUnitOfWorkManager unitOfWorkManager,
IGuidGenerator guidGenerator,
IClock clock,
@ -91,6 +99,7 @@ namespace LINGYUN.Abp.EventBus.CAP
CapPublisher = capPublisher;
CurrentUser = currentUser;
CurrentClient = currentClient;
JsonSerializer = jsonSerializer;
CancellationTokenProvider = cancellationTokenProvider;
CustomDistributedEventSubscriber = customDistributedEventSubscriber;
HandlerFactories = new ConcurrentDictionary<Type, List<IEventHandlerFactory>>();
@ -104,9 +113,7 @@ namespace LINGYUN.Abp.EventBus.CAP
/// <returns></returns>
public override IDisposable Subscribe(Type eventType, IEventHandlerFactory factory)
{
// 自定义的事件订阅者,可以不需要事件注册的事件类型
CustomDistributedEventSubscriber.Subscribe(eventType, factory);
return new DisposeAction(() => CustomDistributedEventSubscriber.UnSubscribe(eventType, factory));
return NullDisposable.Instance;
}
/// <summary>
/// 退订事件
@ -115,27 +122,6 @@ namespace LINGYUN.Abp.EventBus.CAP
/// <param name="action"></param>
public override void Unsubscribe<TEvent>(Func<TEvent, Task> action)
{
Check.NotNull(action, nameof(action));
GetOrCreateHandlerFactories(typeof(TEvent))
.Locking(factories =>
{
factories.RemoveAll(
factory =>
{
if (!(factory is SingleInstanceHandlerFactory singleInstanceFactory))
{
return false;
}
if (!(singleInstanceFactory.HandlerInstance is ActionEventHandler<TEvent> actionHandler))
{
return false;
}
return actionHandler.Action == action;
});
});
}
/// <summary>
/// 退订事件
@ -144,15 +130,6 @@ namespace LINGYUN.Abp.EventBus.CAP
/// <param name="handler">事件处理器</param>
public override void Unsubscribe(Type eventType, IEventHandler handler)
{
GetOrCreateHandlerFactories(eventType)
.Locking(factories =>
{
factories.RemoveAll(
factory =>
factory is SingleInstanceHandlerFactory &&
(factory as SingleInstanceHandlerFactory).HandlerInstance == handler
);
});
}
/// <summary>
/// 退订事件
@ -161,8 +138,6 @@ namespace LINGYUN.Abp.EventBus.CAP
/// <param name="factory">事件处理器工厂</param>
public override void Unsubscribe(Type eventType, IEventHandlerFactory factory)
{
GetOrCreateHandlerFactories(eventType).Locking(factories => factories.Remove(factory));
CustomDistributedEventSubscriber.UnSubscribe(eventType, factory);
}
/// <summary>
/// 退订所有事件
@ -170,7 +145,6 @@ namespace LINGYUN.Abp.EventBus.CAP
/// <param name="eventType">事件类型</param>
public override void UnsubscribeAll(Type eventType)
{
GetOrCreateHandlerFactories(eventType).Locking(factories => factories.Clear());
}
/// <summary>
/// 发布事件
@ -181,16 +155,7 @@ namespace LINGYUN.Abp.EventBus.CAP
protected override async Task PublishToEventBusAsync(Type eventType, object eventData)
{
var eventName = EventNameAttribute.GetNameOrDefault(eventType);
await CapPublisher
.PublishAsync(
eventName, eventData,
new Dictionary<string, string>
{
{ AbpCAPHeaders.UserId, CurrentUser.Id?.ToString() ?? "" },
{ AbpCAPHeaders.ClientId, CurrentClient.Id ?? "" },
{ AbpCAPHeaders.TenantId, CurrentTenant.Id?.ToString() ?? "" },
},
CancellationTokenProvider.FallbackToProvider());
await PublishAsync(eventName, eventData);
}
/// <summary>
/// 获取事件处理器工厂列表
@ -209,19 +174,6 @@ namespace LINGYUN.Abp.EventBus.CAP
return handlerFactoryList.ToArray();
}
private List<IEventHandlerFactory> GetOrCreateHandlerFactories(Type eventType)
{
return HandlerFactories.GetOrAdd(
eventType,
type =>
{
var eventName = EventNameAttribute.GetNameOrDefault(type);
EventTypes[eventName] = type;
return new List<IEventHandlerFactory>();
}
);
}
private static bool ShouldTriggerEventForHandler(Type targetEventType, Type handlerEventType)
{
//Should trigger same type
@ -240,26 +192,53 @@ namespace LINGYUN.Abp.EventBus.CAP
return false;
}
public override Task PublishFromOutboxAsync(OutgoingEventInfo outgoingEvent, OutboxConfig outboxConfig)
public override async Task PublishFromOutboxAsync(OutgoingEventInfo outgoingEvent, OutboxConfig outboxConfig)
{
// cap自行实现
return Task.CompletedTask;
await PublishAsync(outgoingEvent.EventName, outgoingEvent.EventData);
}
public override Task ProcessFromInboxAsync(IncomingEventInfo incomingEvent, InboxConfig inboxConfig)
public override async Task ProcessFromInboxAsync(IncomingEventInfo incomingEvent, InboxConfig inboxConfig)
{
// cap自行实现
return Task.CompletedTask;
var eventType = EventTypes.GetOrDefault(incomingEvent.EventName);
if (eventType == null)
{
return;
}
var eventJson = Encoding.UTF8.GetString(incomingEvent.EventData);
var eventData = JsonSerializer.Deserialize(eventType, eventJson);
var exceptions = new List<Exception>();
await TriggerHandlersAsync(eventType, eventData, exceptions, inboxConfig);
if (exceptions.Any())
{
ThrowOriginalExceptions(eventType, exceptions);
}
}
protected override byte[] Serialize(object eventData)
{
throw new NotImplementedException();
var eventJson = JsonSerializer.Serialize(eventData);
return Encoding.UTF8.GetBytes(eventJson);
}
protected override void AddToUnitOfWork(IUnitOfWork unitOfWork, UnitOfWorkEventRecord eventRecord)
{
unitOfWork.AddOrReplaceDistributedEvent(eventRecord);
}
protected async Task PublishAsync(string eventName, object eventData)
{
await CapPublisher
.PublishAsync(
eventName, eventData,
new Dictionary<string, string>
{
{ AbpCAPHeaders.UserId, CurrentUser.Id?.ToString() ?? "" },
{ AbpCAPHeaders.ClientId, CurrentClient.Id ?? "" },
{ AbpCAPHeaders.TenantId, CurrentTenant.Id?.ToString() ?? "" },
},
CancellationTokenProvider.FallbackToProvider());
}
}
}

13
aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/Microsoft/Extensions/DependencyInjection/ServiceCollectionExtensions.cs

@ -1,11 +1,8 @@
using DotNetCore.CAP;
using DotNetCore.CAP.Internal;
using DotNetCore.CAP.Processor;
using DotNetCore.CAP.Serialization;
using LINGYUN.Abp.EventBus.CAP;
using Microsoft.Extensions.DependencyInjection.Extensions;
using System;
using System.Linq;
namespace Microsoft.Extensions.DependencyInjection
{
@ -23,16 +20,6 @@ namespace Microsoft.Extensions.DependencyInjection
public static IServiceCollection AddCAPEventBus(this IServiceCollection services, Action<CapOptions> capAction)
{
services.AddCap(capAction);
// 移除默认的定时清理过期消息任务
// 默认的五分钟,不可配置,时间间隔过短,使用自定义的后台任务
services.RemoveAll(typeof(CollectorProcessor));
var capProcessingServiceDescriptor = services
.FirstOrDefault(x => typeof(CapProcessingServer).Equals(x.ImplementationType));
if(capProcessingServiceDescriptor != null)
{
services.Remove(capProcessingServiceDescriptor);
}
services.TryAddEnumerable(ServiceDescriptor.Singleton<IProcessingServer, AbpCapProcessingServer>());
// 替换为自己的实现
services.AddSingleton<ISubscribeInvoker, AbpCAPSubscribeInvoker>();
services.AddSingleton<ISerializer, AbpCapSerializer>();

3
aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/appsettings.Development.json

@ -31,7 +31,8 @@
"DefaultGroupName": "BackendAdmin",
"Version": "v1",
"FailedRetryInterval": 300,
"FailedRetryCount": 10
"FailedRetryCount": 10,
"CollectorCleaningInterval": 3600000
},
"MySql": {
"TableNamePrefix": "admin",

3
aspnet-core/services/LY.MicroService.LocalizationManagement.HttpApi.Host/appsettings.Development.json

@ -22,7 +22,8 @@
"DefaultGroupName": "Localization-Management",
"Version": "v1",
"FailedRetryInterval": 300,
"FailedRetryCount": 10
"FailedRetryCount": 10,
"CollectorCleaningInterval": 3600000
},
"MySql": {
"TableNamePrefix": "lta",

3
aspnet-core/services/LY.MicroService.PlatformManagement.HttpApi.Host/appsettings.Development.json

@ -53,7 +53,8 @@
"DefaultGroupName": "Platform",
"Version": "v1",
"FailedRetryInterval": 300,
"FailedRetryCount": 10
"FailedRetryCount": 10,
"CollectorCleaningInterval": 3600000
},
"MySql": {
"TableNamePrefix": "plt",

3
aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/appsettings.Development.json

@ -60,7 +60,8 @@
"DefaultGroupName": "MessageService",
"Version": "v1",
"FailedRetryInterval": 300,
"FailedRetryCount": 10
"FailedRetryCount": 10,
"CollectorCleaningInterval": 3600000
},
"MySql": {
"TableNamePrefix": "msg",

3
aspnet-core/services/LY.MicroService.identityServer.HttpApi.Host/FodyWeavers.xml

@ -1,3 +0,0 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<ConfigureAwait ContinueOnCapturedContext="false" />
</Weavers>

3
aspnet-core/services/LY.MicroService.identityServer.HttpApi.Host/appsettings.Development.json

@ -27,7 +27,8 @@
"DefaultGroupName": "IdentityServer4Admin",
"Version": "v1",
"FailedRetryInterval": 300,
"FailedRetryCount": 10
"FailedRetryCount": 10,
"CollectorCleaningInterval": 3600000
},
"MySql": {
"TableNamePrefix": "ida",

3
aspnet-core/services/LY.MicroService.identityServer/appsettings.Development.json

@ -27,7 +27,8 @@
"DefaultGroupName": "AuthServer",
"Version": "v1",
"FailedRetryInterval": 300,
"FailedRetryCount": 10
"FailedRetryCount": 10,
"CollectorCleaningInterval": 3600000
},
"MySql": {
"TableNamePrefix": "auth",

Loading…
Cancel
Save