Browse Source

feat(dapr): 使dapr代理请求过程可配置

pull/412/head
cKey 4 years ago
parent
commit
8c39a15379
  1. 44
      aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/AbpDaprClientBuilderOptions.cs
  2. 39
      aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/DynamicProxying/AbpDaprClientProxyOptions.cs
  3. 5
      aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/DynamicProxying/DynamicDaprClientProxyInterceptor.cs

44
aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/AbpDaprClientBuilderOptions.cs

@ -1,22 +1,22 @@
using Dapr.Client; using Dapr.Client;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace LINGYUN.Abp.Dapr.Client namespace LINGYUN.Abp.Dapr.Client
{ {
public class AbpDaprClientBuilderOptions public class AbpDaprClientBuilderOptions
{ {
public List<Action<string, DaprClient>> ProxyClientActions { get; } public List<Action<string, DaprClient>> ProxyClientActions { get; }
public List<Action<string, IServiceProvider, DaprClientBuilder>> ProxyClientBuildActions { get; } public List<Action<string, IServiceProvider, DaprClientBuilder>> ProxyClientBuildActions { get; }
internal HashSet<string> ConfiguredProxyClients { get; } internal HashSet<string> ConfiguredProxyClients { get; }
public AbpDaprClientBuilderOptions() public AbpDaprClientBuilderOptions()
{ {
ConfiguredProxyClients = new HashSet<string>(); ConfiguredProxyClients = new HashSet<string>();
ProxyClientActions = new List<Action<string, DaprClient>>(); ProxyClientActions = new List<Action<string, DaprClient>>();
ProxyClientBuildActions = new List<Action<string, IServiceProvider, DaprClientBuilder>>(); ProxyClientBuildActions = new List<Action<string, IServiceProvider, DaprClientBuilder>>();
} }
} }
} }

39
aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/DynamicProxying/AbpDaprClientProxyOptions.cs

@ -1,15 +1,24 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Net.Http;
namespace LINGYUN.Abp.Dapr.Client.DynamicProxying
{ namespace LINGYUN.Abp.Dapr.Client.DynamicProxying
public class AbpDaprClientProxyOptions {
{ public class AbpDaprClientProxyOptions
public Dictionary<Type, DynamicDaprClientProxyConfig> DaprClientProxies { get; set; } {
public Dictionary<Type, DynamicDaprClientProxyConfig> DaprClientProxies { get; set; }
public AbpDaprClientProxyOptions()
{ /// <summary>
DaprClientProxies = new Dictionary<Type, DynamicDaprClientProxyConfig>(); /// 增加一个可配置的请求消息
} /// 参数一: appId
} /// 参数二: HttpRequestMessage
} /// </summary>
public List<Action<string, HttpRequestMessage>> ProxyRequestActions { get; }
public AbpDaprClientProxyOptions()
{
DaprClientProxies = new Dictionary<Type, DynamicDaprClientProxyConfig>();
ProxyRequestActions = new List<Action<string, HttpRequestMessage>>();
}
}
}

5
aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/DynamicProxying/DynamicDaprClientProxyInterceptor.cs

@ -212,6 +212,11 @@ namespace LINGYUN.Abp.Dapr.Client.DynamicProxying
{ {
requestMessage.Headers.Authorization = httpClient.DefaultRequestHeaders.Authorization; requestMessage.Headers.Authorization = httpClient.DefaultRequestHeaders.Authorization;
} }
// 增加一个可配置的请求消息
foreach (var clientRequestAction in ClientProxyOptions.ProxyRequestActions)
{
clientRequestAction(remoteServiceConfig.AppId, requestMessage);
}
var response = await daprClient.InvokeMethodWithResponseAsync(requestMessage, GetCancellationToken()); var response = await daprClient.InvokeMethodWithResponseAsync(requestMessage, GetCancellationToken());

Loading…
Cancel
Save