Browse Source

/

pull/586/head
cKey 4 years ago
parent
commit
804caccaf2
  1. 2
      aspnet-core/LINGYUN.MicroService.TaskManagement.sln
  2. 2
      aspnet-core/modules/cli/LINGYUN.Abp.Cli/LINGYUN.Abp.Cli.csproj
  3. 4
      aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Notifications/LINGYUN/Abp/ExceptionHandling/Notifications/AbpExceptionHandlingNotificationDefinitionProvider.cs
  4. 1
      aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN.Abp.Notifications.csproj
  5. 21
      aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/AbpNotificationCleanupOptions.cs
  6. 24
      aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/AbpNotificationModule.cs
  7. 41
      aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Internal/NotificationCleanupBackgroundWorker.cs
  8. 45
      aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationPublishJob.cs
  9. 20
      aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationPublishJobArgs.cs
  10. 16
      aspnet-core/modules/console/LINGYUN.Abp.Encryption.Console/AbpEncryptionConsoleModule.cs
  11. 5
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/INotificationRepository.cs
  12. 4
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/NotificationStore.cs
  13. 15
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Notifications/EfCoreNotificationRepository.cs
  14. 22
      aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/BackgroundJobs/NotificationCleanupJob.cs
  15. 45
      aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/BackgroundJobs/NotificationPublishJob.cs
  16. 20
      aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/BackgroundJobs/NotificationPublishJobArgs.cs
  17. 7
      aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/EventBus/Distributed/NotificationEventHandler.cs
  18. 8
      aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/LY.MicroService.RealtimeMessage.HttpApi.Host.csproj
  19. 104
      aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/RealtimeMessageHttpApiHostModule.Configure.cs
  20. 151
      aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/RealtimeMessageHttpApiHostModule.cs
  21. 22
      aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/appsettings.Development.json

2
aspnet-core/LINGYUN.MicroService.TaskManagement.sln

@ -44,7 +44,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.TaskManagement.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.BackgroundTasks.TaskManagement", "modules\task-management\LINGYUN.Abp.BackgroundTasks.TaskManagement\LINGYUN.Abp.BackgroundTasks.TaskManagement.csproj", "{7937785C-0D28-46B3-A7E7-0B592821A1F2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.BackgroundTasks.EventBus", "modules\task-management\LINGYUN.Abp.BackgroundTasks.EventBus\LINGYUN.Abp.BackgroundTasks.EventBus.csproj", "{D17DEF79-635B-478D-89D7-32EAE616869A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.BackgroundTasks.EventBus", "modules\task-management\LINGYUN.Abp.BackgroundTasks.EventBus\LINGYUN.Abp.BackgroundTasks.EventBus.csproj", "{D17DEF79-635B-478D-89D7-32EAE616869A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution

2
aspnet-core/modules/cli/LINGYUN.Abp.Cli/LINGYUN.Abp.Cli.csproj

@ -5,7 +5,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<Version>5.2.0</Version>
<Version>5.2.1</Version>
<Copyright>colin</Copyright>
<Description>Use LINGYUN.MicroService.Templates command line</Description>
<PackAsTool>true</PackAsTool>

4
aspnet-core/modules/common/LINGYUN.Abp.ExceptionHandling.Notifications/LINGYUN/Abp/ExceptionHandling/Notifications/AbpExceptionHandlingNotificationDefinitionProvider.cs

@ -19,7 +19,9 @@ namespace LINGYUN.Abp.ExceptionHandling.Notifications
description: L("Notifications:ExceptionNotifier"),
notificationType: NotificationType.System,
lifetime: NotificationLifetime.Persistent,
allowSubscriptionToClients: false);
allowSubscriptionToClients: false)
// TODO: 全局常量
.WithProviders("SignalR");
}
protected LocalizableString L(string name)

1
aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN.Abp.Notifications.csproj

@ -12,7 +12,6 @@
<PackageReference Include="Volo.Abp.EventBus" Version="$(VoloAbpPackageVersion)" />
<PackageReference Include="Volo.Abp.Json" Version="$(VoloAbpPackageVersion)" />
<PackageReference Include="Volo.Abp.BackgroundJobs.Abstractions" Version="$(VoloAbpPackageVersion)" />
<PackageReference Include="Volo.Abp.BackgroundWorkers" Version="$(VoloAbpPackageVersion)" />
</ItemGroup>
<ItemGroup>

21
aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/AbpNotificationCleanupOptions.cs

@ -1,21 +0,0 @@
namespace LINGYUN.Abp.Notifications
{
public class AbpNotificationCleanupOptions
{
/// <summary>
/// 是否启用清理任务
/// 默认:启用
/// </summary>
public bool IsEnabled { get; set; } = true;
/// <summary>
/// 清理时间间隔
/// 默认:30_0000ms
/// </summary>
public int CleanupPeriod { get; set; } = 30_0000;
/// <summary>
/// 清理批次
/// 默认: 200
/// </summary>
public int CleanupBatchSize { get; set; } = 200;
}
}

24
aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/AbpNotificationModule.cs

@ -1,17 +1,12 @@
using LINGYUN.Abp.IdGenerator;
using LINGYUN.Abp.Notifications.Internal;
using LINGYUN.Abp.RealTime;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.BackgroundJobs;
using Volo.Abp.BackgroundWorkers;
using Volo.Abp.Json;
using Volo.Abp.Modularity;
using Volo.Abp.Threading;
namespace LINGYUN.Abp.Notifications
{
@ -30,25 +25,6 @@ namespace LINGYUN.Abp.Notifications
AutoAddDefinitionProviders(context.Services);
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
AsyncHelper.RunSync(() => OnApplicationInitializationAsync(context));
}
public override async Task OnApplicationInitializationAsync(ApplicationInitializationContext context)
{
var options = context.ServiceProvider.GetRequiredService<IOptions<AbpNotificationCleanupOptions>>().Value;
if (options.IsEnabled)
{
await context.ServiceProvider
.GetRequiredService<IBackgroundWorkerManager>()
.AddAsync(
context.ServiceProvider
.GetRequiredService<NotificationCleanupBackgroundWorker>()
);
}
}
private void AutoAddDefinitionProviders(IServiceCollection services)
{
var definitionProviders = new List<Type>();

41
aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Internal/NotificationCleanupBackgroundWorker.cs

@ -1,41 +0,0 @@
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 LINGYUN.Abp.Notifications.Internal
{
internal class NotificationCleanupBackgroundWorker : AsyncPeriodicBackgroundWorkerBase
{
protected AbpNotificationCleanupOptions Options { get; }
public NotificationCleanupBackgroundWorker(
AbpAsyncTimer timer,
IServiceScopeFactory serviceScopeFactory,
IOptions<AbpNotificationCleanupOptions> options)
: base(timer, serviceScopeFactory)
{
Options = options.Value;
timer.Period = Options.CleanupPeriod;
}
protected override async Task DoWorkAsync(PeriodicBackgroundWorkerContext workerContext)
{
try
{
var store = workerContext.ServiceProvider.GetRequiredService<INotificationStore>();
Logger.LogDebug("Before cleanup exprition jobs...");
await store.DeleteNotificationAsync(Options.CleanupBatchSize);
Logger.LogDebug("Exprition jobs cleanup job was successful...");
}
catch (Exception ex)
{
Logger.LogWarning("Exprition jobs cleanup job was failed...");
Logger.LogWarning("Error:{0}", ex.Message);
}
}
}
}

45
aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationPublishJob.cs

@ -1,45 +0,0 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using System;
using System.Threading.Tasks;
using Volo.Abp.BackgroundJobs;
using Volo.Abp.DependencyInjection;
namespace LINGYUN.Abp.Notifications
{
public class NotificationPublishJob : AsyncBackgroundJob<NotificationPublishJobArgs>, ITransientDependency
{
protected AbpNotificationOptions Options { get; }
protected INotificationStore Store { get; }
protected IServiceProvider ServiceProvider { get; }
public NotificationPublishJob(
IOptions<AbpNotificationOptions> options,
INotificationStore store,
IServiceProvider serviceProvider)
{
Store = store;
Options = options.Value;
ServiceProvider = serviceProvider;
}
public override async Task ExecuteAsync(NotificationPublishJobArgs args)
{
var providerType = Type.GetType(args.ProviderType);
if (ServiceProvider.GetRequiredService(providerType) is INotificationPublishProvider publishProvider)
{
var notification = await Store.GetNotificationOrNullAsync(args.TenantId, args.NotificationId);
notification.Data = NotificationDataConverter.Convert(notification.Data);
var notifacationDataMapping = Options.NotificationDataMappings
.GetMapItemOrDefault(notification.Name, publishProvider.Name);
if (notifacationDataMapping != null)
{
notification.Data = notifacationDataMapping.MappingFunc(notification.Data);
}
await publishProvider.PublishAsync(notification, args.UserIdentifiers);
}
}
}
}

20
aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationPublishJobArgs.cs

@ -1,20 +0,0 @@
using System;
using System.Collections.Generic;
namespace LINGYUN.Abp.Notifications
{
public class NotificationPublishJobArgs
{
public Guid? TenantId { get; set; }
public long NotificationId { get; set; }
public string ProviderType { get; set; }
public List<UserIdentifier> UserIdentifiers { get; set; }
public NotificationPublishJobArgs(long id, string providerType, List<UserIdentifier> userIdentifiers, Guid? tenantId = null )
{
NotificationId = id;
ProviderType = providerType;
UserIdentifiers = userIdentifiers;
TenantId = tenantId;
}
}
}

16
aspnet-core/modules/console/LINGYUN.Abp.Encryption.Console/AbpEncryptionConsoleModule.cs

@ -1,12 +1,22 @@
using Volo.Abp.Modularity;
using System.Text;
using Volo.Abp.Modularity;
using Volo.Abp.Security;
using Volo.Abp.Security.Encryption;
namespace LINGYUN.Abp.Encryption.Console
{
[DependsOn(
typeof(AbpSecurityModule))]
public class AbpEncryptionConsoleModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpStringEncryptionOptions>(options =>
{
options.DefaultPassPhrase = "s46c5q55nxpeS8Ra";
options.InitVectorBytes = Encoding.ASCII.GetBytes("s83ng0abvd02js84");
options.DefaultSalt = Encoding.ASCII.GetBytes("sf&5)s3#");
});
}
}
}

5
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/INotificationRepository.cs

@ -1,4 +1,5 @@
using System.Threading;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
@ -10,7 +11,7 @@ namespace LINGYUN.Abp.MessageService.Notifications
long notificationId,
CancellationToken cancellationToken = default);
Task DeleteExpritionAsync(
Task<List<Notification>> GetExpritionAsync(
int batchCount,
CancellationToken cancellationToken = default);
}

4
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/NotificationStore.cs

@ -92,7 +92,9 @@ namespace LINGYUN.Abp.MessageService.Notifications
{
using (var unitOfWork = _unitOfWorkManager.Begin())
{
await _notificationRepository.DeleteExpritionAsync(batchCount, cancellationToken);
var notitications = await _notificationRepository.GetExpritionAsync(batchCount, cancellationToken);
await _notificationRepository.DeleteManyAsync(notitications);
await unitOfWork.CompleteAsync(cancellationToken);
}

15
aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Notifications/EfCoreNotificationRepository.cs

@ -1,6 +1,7 @@
using LINGYUN.Abp.MessageService.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
@ -19,20 +20,14 @@ namespace LINGYUN.Abp.MessageService.Notifications
{
}
public async Task DeleteExpritionAsync(
public async Task<List<Notification>> GetExpritionAsync(
int batchCount,
CancellationToken cancellationToken = default)
{
var dbSet = await GetDbSetAsync();
var batchDeleteNoticeWithIds = await dbSet
.Where(x => x.ExpirationTime <= DateTime.Now)
return await (await GetDbSetAsync())
.Where(x => x.ExpirationTime.Value.CompareTo(DateTime.Now) <= 0)
.Take(batchCount)
.Select(x => new Notification(x.Id))
.AsNoTracking()
.ToArrayAsync(GetCancellationToken(cancellationToken));
dbSet.AttachRange(batchDeleteNoticeWithIds);
dbSet.RemoveRange(batchDeleteNoticeWithIds);
.ToListAsync(GetCancellationToken(cancellationToken));
}
public async Task<Notification> GetByIdAsync(

22
aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/BackgroundJobs/NotificationCleanupJob.cs

@ -0,0 +1,22 @@
using LINGYUN.Abp.BackgroundTasks;
using LINGYUN.Abp.Notifications;
using System.Threading.Tasks;
namespace LY.MicroService.RealtimeMessage.BackgroundJobs;
public class NotificationCleanupJob : IJobRunnable
{
/// <summary>
/// 每次清除记录大小
/// </summary>
public const string PropertyBatchCount = "BatchCount";
public async virtual Task ExecuteAsync(JobRunnableContext context)
{
var count = context.GetJobData<int>(PropertyBatchCount);
var store = context.GetRequiredService<INotificationStore>();
await store.DeleteNotificationAsync(count);
}
}

45
aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/BackgroundJobs/NotificationPublishJob.cs

@ -0,0 +1,45 @@
using LINGYUN.Abp.Notifications;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using System;
using System.Threading.Tasks;
using Volo.Abp.BackgroundJobs;
using Volo.Abp.DependencyInjection;
namespace LY.MicroService.RealtimeMessage.BackgroundJobs;
public class NotificationPublishJob : AsyncBackgroundJob<NotificationPublishJobArgs>, ITransientDependency
{
protected AbpNotificationOptions Options { get; }
protected INotificationStore Store { get; }
protected IServiceProvider ServiceProvider { get; }
public NotificationPublishJob(
IOptions<AbpNotificationOptions> options,
INotificationStore store,
IServiceProvider serviceProvider)
{
Store = store;
Options = options.Value;
ServiceProvider = serviceProvider;
}
public override async Task ExecuteAsync(NotificationPublishJobArgs args)
{
var providerType = Type.GetType(args.ProviderType);
if (ServiceProvider.GetRequiredService(providerType) is INotificationPublishProvider publishProvider)
{
var notification = await Store.GetNotificationOrNullAsync(args.TenantId, args.NotificationId);
notification.Data = NotificationDataConverter.Convert(notification.Data);
var notifacationDataMapping = Options.NotificationDataMappings
.GetMapItemOrDefault(notification.Name, publishProvider.Name);
if (notifacationDataMapping != null)
{
notification.Data = notifacationDataMapping.MappingFunc(notification.Data);
}
await publishProvider.PublishAsync(notification, args.UserIdentifiers);
}
}
}

20
aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/BackgroundJobs/NotificationPublishJobArgs.cs

@ -0,0 +1,20 @@
using LINGYUN.Abp.Notifications;
using System;
using System.Collections.Generic;
namespace LY.MicroService.RealtimeMessage.BackgroundJobs;
public class NotificationPublishJobArgs
{
public Guid? TenantId { get; set; }
public long NotificationId { get; set; }
public string ProviderType { get; set; }
public List<UserIdentifier> UserIdentifiers { get; set; }
public NotificationPublishJobArgs(long id, string providerType, List<UserIdentifier> userIdentifiers, Guid? tenantId = null)
{
NotificationId = id;
ProviderType = providerType;
UserIdentifiers = userIdentifiers;
TenantId = tenantId;
}
}

7
aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/EventBus/Distributed/NotificationEventHandler.cs

@ -1,4 +1,5 @@
using LINGYUN.Abp.Notifications;
using LY.MicroService.RealtimeMessage.BackgroundJobs;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
@ -121,6 +122,12 @@ namespace LY.MicroService.RealtimeMessage.EventBus.Distributed
var providers = Enumerable
.Reverse(NotificationPublishProviderManager.Providers);
// 过滤用户指定提供者
if (notification.Providers.Any())
{
providers = providers.Where(p => notification.Providers.Contains(p.Name));
}
await PublishFromProvidersAsync(providers, eventData.Users, notificationInfo);
}
}

8
aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/LY.MicroService.RealtimeMessage.HttpApi.Host.csproj

@ -19,6 +19,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="$(MicrosoftPackageVersion)" />
<PackageReference Include="Quartz.Serialization.Json" Version="$(QuartzNETPackageVersion)" />
<PackageReference Include="Serilog.AspNetCore" Version="$(SerilogAspNetCorePackageVersion)" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="$(SerilogEnrichersEnvironmentPackageVersion)" />
<PackageReference Include="Serilog.Enrichers.Assembly" Version="$(SerilogEnrichersAssemblyPackageVersion)" />
@ -43,16 +44,15 @@
<ProjectReference Include="..\..\modules\auditing\LINGYUN.Abp.AuditLogging.Elasticsearch\LINGYUN.Abp.AuditLogging.Elasticsearch.csproj" />
<ProjectReference Include="..\..\modules\authorization\LINGYUN.Abp.Authorization.OrganizationUnits\LINGYUN.Abp.Authorization.OrganizationUnits.csproj" />
<ProjectReference Include="..\..\modules\common\LINGYUN.Abp.AspNetCore.HttpOverrides\LINGYUN.Abp.AspNetCore.HttpOverrides.csproj" />
<ProjectReference Include="..\..\modules\common\LINGYUN.Abp.BackgroundWorkers.Hangfire\LINGYUN.Abp.BackgroundWorkers.Hangfire.csproj" />
<ProjectReference Include="..\..\modules\common\LINGYUN.Abp.Data.DbMigrator\LINGYUN.Abp.Data.DbMigrator.csproj" />
<ProjectReference Include="..\..\modules\common\LINGYUN.Abp.ExceptionHandling.Notifications\LINGYUN.Abp.ExceptionHandling.Notifications.csproj" />
<ProjectReference Include="..\..\modules\common\LINGYUN.Abp.Hangfire.Dashboard\LINGYUN.Abp.Hangfire.Dashboard.csproj" />
<ProjectReference Include="..\..\modules\common\LINGYUN.Abp.Hangfire.MySqlStorage\LINGYUN.Abp.Hangfire.Storage.MySql.csproj" />
<ProjectReference Include="..\..\modules\common\LINGYUN.Abp.BackgroundJobs.Hangfire\LINGYUN.Abp.BackgroundJobs.Hangfire.csproj" />
<ProjectReference Include="..\..\modules\common\LINGYUN.Abp.EventBus.CAP\LINGYUN.Abp.EventBus.CAP.csproj" />
<ProjectReference Include="..\..\modules\common\LINGYUN.Abp.IM.SignalR\LINGYUN.Abp.IM.SignalR.csproj" />
<ProjectReference Include="..\..\modules\common\LINGYUN.Abp.Notifications.SignalR\LINGYUN.Abp.Notifications.SignalR.csproj" />
<ProjectReference Include="..\..\modules\common\LINGYUN.Abp.Notifications.Sms\LINGYUN.Abp.Notifications.Sms.csproj" />
<ProjectReference Include="..\..\modules\task-management\LINGYUN.Abp.BackgroundTasks.Quartz\LINGYUN.Abp.BackgroundTasks.Quartz.csproj" />
<ProjectReference Include="..\..\modules\task-management\LINGYUN.Abp.BackgroundTasks.ExceptionHandling\LINGYUN.Abp.BackgroundTasks.ExceptionHandling.csproj" />
<ProjectReference Include="..\..\modules\task-management\LINGYUN.Abp.TaskManagement.EntityFrameworkCore\LINGYUN.Abp.TaskManagement.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\modules\localization\LINGYUN.Abp.Localization.CultureMap\LINGYUN.Abp.Localization.CultureMap.csproj" />
<ProjectReference Include="..\..\modules\logging\LINGYUN.Abp.Serilog.Enrichers.Application\LINGYUN.Abp.Serilog.Enrichers.Application.csproj" />
<ProjectReference Include="..\..\modules\logging\LINGYUN.Abp.Serilog.Enrichers.UniqueId\LINGYUN.Abp.Serilog.Enrichers.UniqueId.csproj" />

104
aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/RealtimeMessageHttpApiHostModule.Configure.cs

@ -1,30 +1,26 @@
using DotNetCore.CAP;
using Hangfire;
using Hangfire.Dashboard;
using LINGYUN.Abp.BackgroundTasks;
using LINGYUN.Abp.ExceptionHandling;
using LINGYUN.Abp.Hangfire.Dashboard.Authorization;
using LINGYUN.Abp.Localization.CultureMap;
using LINGYUN.Abp.MessageService.Localization;
using LINGYUN.Abp.MessageService.Permissions;
using LINGYUN.Abp.Serilog.Enrichers.Application;
using LINGYUN.Abp.Serilog.Enrichers.UniqueId;
using LY.MicroService.RealtimeMessage.BackgroundJobs;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Caching.StackExchangeRedis;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;
using Quartz;
using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Encodings.Web;
using System.Text.Unicode;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.AspNetCore.Auditing;
using Volo.Abp.Auditing;
using Volo.Abp.Caching;
using Volo.Abp.EntityFrameworkCore;
@ -33,16 +29,15 @@ using Volo.Abp.Json;
using Volo.Abp.Json.SystemTextJson;
using Volo.Abp.Localization;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Quartz;
using Volo.Abp.Threading;
using Volo.Abp.Timing;
using Volo.Abp.VirtualFileSystem;
using HangfireDashboardOptions = Hangfire.DashboardOptions;
namespace LY.MicroService.RealtimeMessage;
public partial class RealtimeMessageHttpApiHostModule
{
protected static string[] PrefixTokenQueryStrings = new [] { "/signalr-hubs", "/hangfire" };
protected const string ApplicationName = "MessageService";
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();
@ -56,7 +51,7 @@ public partial class RealtimeMessageHttpApiHostModule
private void PreConfigureApp()
{
AbpSerilogEnrichersConsts.ApplicationName = "MessageService";
AbpSerilogEnrichersConsts.ApplicationName = ApplicationName;
PreConfigure<AbpSerilogEnrichersUniqueIdOptions>(options =>
{
@ -84,16 +79,41 @@ public partial class RealtimeMessageHttpApiHostModule
});
}
private void PreCongifureHangfire()
private void PreConfigureQuartz(IConfiguration configuration)
{
PreConfigure<HangfireDashboardOptions>(options =>
PreConfigure<AbpQuartzOptions>(options =>
{
options.AsyncAuthorization = new IDashboardAsyncAuthorizationFilter[]
// 如果使用持久化存储, 则配置quartz持久层
if (configuration.GetSection("Quartz:UsePersistentStore").Get<bool>())
{
new DashboardAuthorizationFilter(
MessageServicePermissions.Hangfire.Dashboard,
MessageServicePermissions.Hangfire.ManageQueue)
};
var settings = configuration.GetSection("Quartz:Properties").Get<Dictionary<string, string>>();
if (settings != null)
{
foreach (var setting in settings)
{
options.Properties[setting.Key] = setting.Value;
}
}
options.Configurator += (config) =>
{
config.UsePersistentStore(store =>
{
store.UseProperties = false;
store.UseJsonSerializer();
});
};
}
});
}
private void ConfigureBackgroundTasks()
{
Configure<AbpBackgroundTasksOptions>(options =>
{
options.NodeName = ApplicationName;
options.AddProvider<NotificationCleanupJob>("NotificationCleanupJob");
});
}
@ -139,14 +159,9 @@ public partial class RealtimeMessageHttpApiHostModule
private void ConfigureAuditing(IConfiguration configuration)
{
Configure<AbpAspNetCoreAuditingOptions>(options =>
{
options.IgnoredUrls.AddIfNotContains("/hangfire");
});
Configure<AbpAuditingOptions>(options =>
{
options.ApplicationName = "MessageService";
options.ApplicationName = ApplicationName;
// 是否启用实体变更记录
var entitiesChangedConfig = configuration.GetSection("App:TrackingEntitiesChanged");
if (entitiesChangedConfig.Exists() && entitiesChangedConfig.Get<bool>())
@ -300,42 +315,6 @@ public partial class RealtimeMessageHttpApiHostModule
options.Authority = configuration["AuthServer:Authority"];
options.RequireHttpsMetadata = false;
options.Audience = configuration["AuthServer:ApiName"];
options.Events = new JwtBearerEvents
{
OnMessageReceived = context =>
{
var accessToken = context.Request.Query["access_token"];
var path = context.HttpContext.Request.Path;
if (!string.IsNullOrEmpty(accessToken) &&
PrefixTokenQueryStrings.Any(prefix => path.StartsWithSegments(prefix)))
{
// 解决仪表板自定义授权问题
context.Token = accessToken;
var clock = context.HttpContext.RequestServices.GetRequiredService<IClock>();
var protectedProvider = context.HttpContext.RequestServices.GetRequiredService<IDataProtectionProvider>();
var protector = protectedProvider.CreateProtector("_hangfire_tk");
var tokenCookies = protector.Protect(accessToken);
context.HttpContext.Response.Cookies.Append(
"_hangfire_tk",
tokenCookies,
new CookieOptions
{
Expires = clock.Now.AddMinutes(10)
});
}
if (context.Token.IsNullOrWhiteSpace() &&
context.Request.Cookies.TryGetValue("_hangfire_tk", out var protectedToken))
{
var protectedProvider = context.HttpContext.RequestServices.GetRequiredService<IDataProtectionProvider>();
var protector = protectedProvider.CreateProtector("_hangfire_tk");
context.Token = protector.Unprotect(protectedToken);
}
return Task.CompletedTask;
},
};
});
if (!isDevelopment)
@ -347,9 +326,4 @@ public partial class RealtimeMessageHttpApiHostModule
.PersistKeysToStackExchangeRedis(redis, "LINGYUN.Abp.Application:DataProtection:Protection-Keys");
}
}
private void ConfigureHangfireServer(IServiceCollection services)
{
services.AddHangfireServer();
}
}

151
aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/RealtimeMessageHttpApiHostModule.cs

@ -1,14 +1,12 @@
using DotNetCore.CAP;
using Hangfire;
using LINGYUN.Abp.AspNetCore.HttpOverrides;
using LINGYUN.Abp.AuditLogging.Elasticsearch;
using LINGYUN.Abp.Authorization.OrganizationUnits;
using LINGYUN.Abp.BackgroundJobs.Hangfire;
using LINGYUN.Abp.BackgroundWorkers.Hangfire;
using LINGYUN.Abp.BackgroundTasks.ExceptionHandling;
using LINGYUN.Abp.BackgroundTasks.Quartz;
using LINGYUN.Abp.Data.DbMigrator;
using LINGYUN.Abp.EventBus.CAP;
using LINGYUN.Abp.ExceptionHandling.Notifications;
using LINGYUN.Abp.Hangfire.Storage.MySql;
using LINGYUN.Abp.Identity.WeChat;
using LINGYUN.Abp.IM.SignalR;
using LINGYUN.Abp.Localization.CultureMap;
@ -21,6 +19,7 @@ using LINGYUN.Abp.Notifications.WeChat.MiniProgram;
using LINGYUN.Abp.Saas.EntityFrameworkCore;
using LINGYUN.Abp.Serilog.Enrichers.Application;
using LINGYUN.Abp.Serilog.Enrichers.UniqueId;
using LINGYUN.Abp.TaskManagement.EntityFrameworkCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
@ -37,9 +36,9 @@ using Volo.Abp.Modularity;
using Volo.Abp.PermissionManagement.EntityFrameworkCore;
using Volo.Abp.SettingManagement.EntityFrameworkCore;
namespace LY.MicroService.RealtimeMessage
{
[DependsOn(
namespace LY.MicroService.RealtimeMessage;
[DependsOn(
typeof(AbpSerilogEnrichersApplicationModule),
typeof(AbpSerilogEnrichersUniqueIdModule),
typeof(AbpAspNetCoreSerilogModule),
@ -48,6 +47,9 @@ namespace LY.MicroService.RealtimeMessage
typeof(AbpMessageServiceApplicationModule),
typeof(AbpMessageServiceHttpApiModule),
typeof(AbpIdentityWeChatModule),
typeof(AbpBackgroundTasksQuartzModule),
typeof(AbpBackgroundTasksExceptionHandlingModule),
typeof(TaskManagementEntityFrameworkCoreModule),
typeof(AbpMessageServiceEntityFrameworkCoreModule),
typeof(AbpIdentityEntityFrameworkCoreModule),
typeof(AbpSaasEntityFrameworkCoreModule),
@ -57,9 +59,6 @@ namespace LY.MicroService.RealtimeMessage
typeof(AbpDataDbMigratorModule),
typeof(AbpAspNetCoreAuthenticationJwtBearerModule),
typeof(AbpAuthorizationOrganizationUnitsModule),
typeof(AbpHangfireMySqlStorageModule),
typeof(AbpBackgroundJobsHangfireModule),
typeof(AbpBackgroundWorkersHangfireModule),
typeof(AbpBackgroundWorkersModule),
typeof(AbpIMSignalRModule),
typeof(AbpNotificationsSmsModule),
@ -72,79 +71,75 @@ namespace LY.MicroService.RealtimeMessage
typeof(AbpLocalizationCultureMapModule),
typeof(AbpAutofacModule)
)]
public partial class RealtimeMessageHttpApiHostModule : AbpModule
{
private const string DefaultCorsPolicyName = "Default";
public partial class RealtimeMessageHttpApiHostModule : AbpModule
{
private const string DefaultCorsPolicyName = "Default";
public override void PreConfigureServices(ServiceConfigurationContext context)
{
var configuration = context.Services.GetConfiguration();
public override void PreConfigureServices(ServiceConfigurationContext context)
{
var configuration = context.Services.GetConfiguration();
PreConfigureApp();
PreConfigureFeature();
PreCongifureHangfire();
PreConfigureCAP(configuration);
}
PreConfigureApp();
PreConfigureFeature();
PreConfigureCAP(configuration);
PreConfigureQuartz(configuration);
}
public override void ConfigureServices(ServiceConfigurationContext context)
{
var hostingEnvironment = context.Services.GetHostingEnvironment();
var configuration = context.Services.GetConfiguration();
public override void ConfigureServices(ServiceConfigurationContext context)
{
var hostingEnvironment = context.Services.GetHostingEnvironment();
var configuration = context.Services.GetConfiguration();
ConfigureDbContext();
ConfigureLocalization();
ConfigureJsonSerializer();
ConfigreExceptionHandling();
ConfigureVirtualFileSystem();
ConfigureCaching(configuration);
ConfigureAuditing(configuration);
ConfigureSwagger(context.Services);
ConfigureMultiTenancy(configuration);
ConfigureHangfireServer(context.Services);
ConfigureCors(context.Services, configuration);
ConfigureSeedWorker(context.Services, hostingEnvironment.IsDevelopment());
ConfigureSecurity(context.Services, configuration, hostingEnvironment.IsDevelopment());
}
ConfigureDbContext();
ConfigureLocalization();
ConfigureJsonSerializer();
ConfigureBackgroundTasks();
ConfigreExceptionHandling();
ConfigureVirtualFileSystem();
ConfigureCaching(configuration);
ConfigureAuditing(configuration);
ConfigureSwagger(context.Services);
ConfigureMultiTenancy(configuration);
ConfigureCors(context.Services, configuration);
ConfigureSeedWorker(context.Services, hostingEnvironment.IsDevelopment());
ConfigureSecurity(context.Services, configuration, hostingEnvironment.IsDevelopment());
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
var app = context.GetApplicationBuilder();
// http调用链
app.UseCorrelationId();
// 虚拟文件系统
app.UseStaticFiles();
// 路由
app.UseRouting();
// 跨域
app.UseCors(DefaultCorsPolicyName);
// 认证
app.UseAuthentication();
app.UseAbpClaimsMap();
// jwt
app.UseJwtTokenMiddleware();
// 多租户
app.UseMultiTenancy();
// 本地化
app.UseMapRequestLocalization();
// 授权
app.UseAuthorization();
// Cap Dashboard
app.UseCapDashboard();
// Swagger
app.UseSwagger();
// Swagger可视化界面
app.UseSwaggerUI(options =>
{
var app = context.GetApplicationBuilder();
// http调用链
app.UseCorrelationId();
// 虚拟文件系统
app.UseStaticFiles();
// 路由
app.UseRouting();
// 跨域
app.UseCors(DefaultCorsPolicyName);
// 认证
app.UseAuthentication();
app.UseAbpClaimsMap();
// jwt
app.UseJwtTokenMiddleware();
// 多租户
app.UseMultiTenancy();
// 本地化
app.UseMapRequestLocalization();
// 授权
app.UseAuthorization();
// Cap Dashboard
app.UseCapDashboard();
// Swagger
app.UseSwagger();
// Swagger可视化界面
app.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Support Realtime Message API");
});
// 审计日志
app.UseAuditing();
app.UseAbpSerilogEnrichers();
// 将在 2.0.0版本移除
// app.UseHangfireServer();
app.UseHangfireDashboard();
// 路由
app.UseConfiguredEndpoints();
}
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Support Realtime Message API");
});
// 审计日志
app.UseAuditing();
app.UseAbpSerilogEnrichers();
// 路由
app.UseConfiguredEndpoints();
}
}

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

@ -25,6 +25,7 @@
"ConnectionStrings": {
"Default": "Server=127.0.0.1;Database=Messages;User Id=root;Password=123456",
"MessageService": "Server=127.0.0.1;Database=Messages;User Id=root;Password=123456",
"TaskManagement": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456",
"AbpIdentity": "Server=127.0.0.1;Database=IdentityServer;User Id=root;Password=123456",
"AbpSaas": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456",
"AbpSettingManagement": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456",
@ -39,13 +40,19 @@
"Authority": "http://127.0.0.1:44385/",
"ApiName": "lingyun-abp-application"
},
"Hangfire": {
"MySql": {
"Connection": "Server=127.0.0.1;Database=Messages;User Id=root;Password=123456;Allow User Variables=true",
"TablePrefix": "AppHangfire"
},
"Dashboard": {
"WhiteList": "http://127.0.0.1:30000"
"Quartz": {
"UsePersistentStore": false,
"Properties": {
"quartz.jobStore.dataSource": "tkm",
"quartz.jobStore.type": "Quartz.Impl.AdoJobStore.JobStoreTX,Quartz",
"quartz.jobStore.driverDelegateType": "Quartz.Impl.AdoJobStore.MySQLDelegate,Quartz",
"quartz.dataSource.tkm.connectionString": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456",
"quartz.dataSource.tkm.connectionStringName": "TaskManagement",
"quartz.dataSource.tkm.provider": "MySqlConnector",
"quartz.jobStore.clustered": "true",
"quartz.serializer.type": "json",
"quartz.scheduler.instanceName": "message-service",
"quartz.scheduler.instanceId": "3c36620a-d8c5-4c89-9828-78f33547751d"
}
},
"Notifications": {
@ -90,7 +97,6 @@
"Override": {
"Microsoft.EntityFrameworkCore": "Warning",
"DotNetCore.CAP": "Debug",
"Hangfire.Server": "Warning",
"System": "Warning",
"Microsoft": "Warning",
"Microsoft.AspNetCore.SignalR": "Debug",

Loading…
Cancel
Save