Browse Source

feat(dapr): 使dapr actor runtime可配置

pull/478/head
cKey 4 years ago
parent
commit
ed1e22b5bd
  1. 1
      apps/vue/vite.config.ts
  2. 4
      aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors.AspNetCore/LINGYUN/Abp/Dapr/Actors/AspNetCore/AbpDaprActorsAspNetCoreModule.cs
  3. 1
      aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/AbpDaprActorsModule.cs
  4. 52
      aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/DaprRemoteServiceConfigurationExtensions.cs
  5. 9
      aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/DynamicProxying/DynamicDaprActorProxyInterceptor.cs
  6. 5
      aspnet-core/modules/task-management/LINGYUN.Abp.BackgroundTasks.Quartz/LINGYUN/Abp/BackgroundTasks/Quartz/AbpBackgroundTasksQuartzModule.cs

1
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: {

4
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<ActorRuntimeOptions>();
services.AddActors(options =>
{
preActions.Configure(options);
options.Actors.AddIfNotContains(actorRegistrations);
});
}

1
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);
}
}

52
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;
}
}

9
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<AbpDaprActorProxyOptions> daprActorProxyOptions,
IOptions<AbpSystemTextJsonSerializerOptions> 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<DynamicDaprActorProxyInterceptor<TService>>.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,
};
// 自定义请求处理器

5
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<QuartzJobListener>());
_scheduler.ListenerManager.AddTriggerListener(context.ServiceProvider.GetRequiredService<QuartzTriggerListener>());
}
}

Loading…
Cancel
Save