From ed1e22b5bdc929be712aaa22844174d641c6b806 Mon Sep 17 00:00:00 2001 From: cKey <35512826+colinin@users.noreply.github.com> Date: Fri, 21 Jan 2022 15:36:46 +0800 Subject: [PATCH] =?UTF-8?q?feat(dapr):=20=E4=BD=BFdapr=20actor=20runtime?= =?UTF-8?q?=E5=8F=AF=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/vue/vite.config.ts | 1 + .../AbpDaprActorsAspNetCoreModule.cs | 4 +- .../Abp/Dapr/Actors/AbpDaprActorsModule.cs | 1 - ...aprRemoteServiceConfigurationExtensions.cs | 52 +++++++++++++++++++ .../DynamicDaprActorProxyInterceptor.cs | 9 +++- .../Quartz/AbpBackgroundTasksQuartzModule.cs | 5 +- 6 files changed, 65 insertions(+), 7 deletions(-) create mode 100644 aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/DaprRemoteServiceConfigurationExtensions.cs diff --git a/apps/vue/vite.config.ts b/apps/vue/vite.config.ts index e6305e221..bd28b8512 100644 --- a/apps/vue/vite.config.ts +++ b/apps/vue/vite.config.ts @@ -61,6 +61,7 @@ export default ({ command, mode }: ConfigEnv): UserConfig => { }, build: { target: 'es2015', + cssTarget: 'chrome86', outDir: OUTPUT_DIR, terserOptions: { compress: { diff --git a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors.AspNetCore/LINGYUN/Abp/Dapr/Actors/AspNetCore/AbpDaprActorsAspNetCoreModule.cs b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors.AspNetCore/LINGYUN/Abp/Dapr/Actors/AspNetCore/AbpDaprActorsAspNetCoreModule.cs index 4d7c86251..db366e498 100644 --- a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors.AspNetCore/LINGYUN/Abp/Dapr/Actors/AspNetCore/AbpDaprActorsAspNetCoreModule.cs +++ b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors.AspNetCore/LINGYUN/Abp/Dapr/Actors/AspNetCore/AbpDaprActorsAspNetCoreModule.cs @@ -44,9 +44,11 @@ namespace LINGYUN.Abp.Dapr.Actors.AspNetCore actorRegistrations.Add(actorRegistration); } }); - + // 使Actor Runtime可配置 + var preActions = services.GetPreConfigureActions(); services.AddActors(options => { + preActions.Configure(options); options.Actors.AddIfNotContains(actorRegistrations); }); } diff --git a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/AbpDaprActorsModule.cs b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/AbpDaprActorsModule.cs index fcdaefda4..a6ffce422 100644 --- a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/AbpDaprActorsModule.cs +++ b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/AbpDaprActorsModule.cs @@ -16,7 +16,6 @@ namespace LINGYUN.Abp.Dapr.Actors public override void ConfigureServices(ServiceConfigurationContext context) { - var configuration = context.Services.GetConfiguration(); context.Services.AddHttpClient(DaprHttpClient); } } diff --git a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/DaprRemoteServiceConfigurationExtensions.cs b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/DaprRemoteServiceConfigurationExtensions.cs new file mode 100644 index 000000000..edb32a620 --- /dev/null +++ b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/DaprRemoteServiceConfigurationExtensions.cs @@ -0,0 +1,52 @@ +using JetBrains.Annotations; +using System.Collections.Generic; +using Volo.Abp; +using Volo.Abp.Http.Client; + +namespace LINGYUN.Abp.Dapr.Actors; + +public static class DaprRemoteServiceConfigurationExtensions +{ + public const string RequestTimeOut = "DaprTimeout"; + public const string DaprApiToken = "DaprApiToken"; + + [CanBeNull] + public static string GetApiToken([NotNull] this RemoteServiceConfiguration configuration) + { + Check.NotNullOrEmpty(configuration, nameof(configuration)); + + return configuration.GetOrDefault(DaprApiToken); + } + + public static RemoteServiceConfiguration SetApiToken([NotNull] this RemoteServiceConfiguration configuration, [NotNull] string value) + { + Check.NotNullOrEmpty(configuration, nameof(configuration)); + Check.NotNullOrEmpty(value, nameof(value)); + + configuration[DaprApiToken] = value; + return configuration; + } + + [NotNull] + public static int GetRequestTimeOut([NotNull] this RemoteServiceConfiguration configuration) + { + Check.NotNullOrEmpty(configuration, nameof(configuration)); + + configuration.TryGetValue("DaprTimeout", out var timeOutValue); + if (!int.TryParse(timeOutValue ?? "30000", out var timeOut)) + { + timeOut = 30000; + } + + return timeOut; + } + + public static RemoteServiceConfiguration SetRequestTimeOut([NotNull] this RemoteServiceConfiguration configuration, [NotNull] string value) + { + Check.NotNullOrEmpty(configuration, nameof(configuration)); + Check.NotNullOrEmpty(value, nameof(value)); + + configuration[RequestTimeOut] = value; + return configuration; + } +} diff --git a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/DynamicProxying/DynamicDaprActorProxyInterceptor.cs b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/DynamicProxying/DynamicDaprActorProxyInterceptor.cs index 1f99521a3..130caedb8 100644 --- a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/DynamicProxying/DynamicDaprActorProxyInterceptor.cs +++ b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/DynamicProxying/DynamicDaprActorProxyInterceptor.cs @@ -16,6 +16,7 @@ using Volo.Abp.Http; using Volo.Abp.Http.Client; using Volo.Abp.Http.Client.Authentication; using Volo.Abp.Http.Client.Proxying; +using Volo.Abp.Json.SystemTextJson; using Volo.Abp.MultiTenancy; using Volo.Abp.Threading; @@ -25,6 +26,7 @@ namespace LINGYUN.Abp.Dapr.Actors.DynamicProxying where TService: IActor { protected ICurrentTenant CurrentTenant { get; } + protected AbpSystemTextJsonSerializerOptions JsonSerializerOptions { get; } protected AbpDaprActorProxyOptions DaprActorProxyOptions { get; } protected IProxyHttpClientFactory HttpClientFactory { get; } protected IRemoteServiceHttpClientAuthenticator ClientAuthenticator { get; } @@ -33,6 +35,7 @@ namespace LINGYUN.Abp.Dapr.Actors.DynamicProxying public DynamicDaprActorProxyInterceptor( IOptions daprActorProxyOptions, + IOptions jsonSerializerOptions, IProxyHttpClientFactory httpClientFactory, IRemoteServiceHttpClientAuthenticator clientAuthenticator, IRemoteServiceConfigurationProvider remoteServiceConfigurationProvider, @@ -42,6 +45,7 @@ namespace LINGYUN.Abp.Dapr.Actors.DynamicProxying HttpClientFactory = httpClientFactory; ClientAuthenticator = clientAuthenticator; DaprActorProxyOptions = daprActorProxyOptions.Value; + JsonSerializerOptions = jsonSerializerOptions.Value; RemoteServiceConfigurationProvider = remoteServiceConfigurationProvider; Logger = NullLogger>.Instance; @@ -79,7 +83,10 @@ namespace LINGYUN.Abp.Dapr.Actors.DynamicProxying var actorProxyOptions = new ActorProxyOptions { - HttpEndpoint = remoteServiceConfig.BaseUrl + HttpEndpoint = remoteServiceConfig.BaseUrl, + RequestTimeout = TimeSpan.FromMilliseconds(remoteServiceConfig.GetRequestTimeOut()), + DaprApiToken = remoteServiceConfig.GetApiToken(), + JsonSerializerOptions = JsonSerializerOptions.JsonSerializerOptions, }; // 自定义请求处理器 diff --git a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Quartz/LINGYUN/Abp/BackgroundTasks/Quartz/AbpBackgroundTasksQuartzModule.cs b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Quartz/LINGYUN/Abp/BackgroundTasks/Quartz/AbpBackgroundTasksQuartzModule.cs index da7045354..0d129a06f 100644 --- a/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Quartz/LINGYUN/Abp/BackgroundTasks/Quartz/AbpBackgroundTasksQuartzModule.cs +++ b/aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Quartz/LINGYUN/Abp/BackgroundTasks/Quartz/AbpBackgroundTasksQuartzModule.cs @@ -1,7 +1,5 @@ -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; using Quartz; -using System.Collections.Specialized; using Volo.Abp; using Volo.Abp.Modularity; using Volo.Abp.Quartz; @@ -18,6 +16,5 @@ public class AbpBackgroundTasksQuartzModule : AbpModule _scheduler.ListenerManager.AddJobListener(context.ServiceProvider.GetRequiredService()); _scheduler.ListenerManager.AddTriggerListener(context.ServiceProvider.GetRequiredService()); - } }