mirror of https://github.com/dapr/dotnet-sdk.git
Refactor DaprWorkflowClientBuilderFactory and WorkflowRuntimeOptions (#1244)
This commit refactors the DaprWorkflowClientBuilderFactory and WorkflowRuntimeOptions classes. In DaprWorkflowClientBuilderFactory: - Added a new method, UseGrpcChannelOptions, to allow the use of custom GrpcChannelOptions for creating the GrpcChannel. - Updated the UseGrpc method to use the GrpcChannelOptions provided by the WorkflowRuntimeOptions. In WorkflowRuntimeOptions: - Added a new property, GrpcChannelOptions, to store the custom GrpcChannelOptions. - Added a new method, UseGrpcChannelOptions, to set the GrpcChannelOptions. These changes improve the flexibility and customization options for the Dapr workflow client. Signed-off-by: Michiel van Praat <michiel.vanpraat@humandigital.nl> Co-authored-by: Michiel van Praat <michiel.vanpraat@humandigital.nl>
This commit is contained in:
parent
7356c9dea2
commit
e7d3c47615
|
@ -50,6 +50,9 @@ internal sealed class DaprWorkflowClientBuilderFactory
|
|||
{
|
||||
_services.AddDurableTaskClient(builder =>
|
||||
{
|
||||
WorkflowRuntimeOptions options = new();
|
||||
configure?.Invoke(options);
|
||||
|
||||
var apiToken = DaprDefaults.GetDefaultDaprApiToken(_configuration);
|
||||
var grpcEndpoint = DaprDefaults.GetDefaultGrpcEndpoint(_configuration);
|
||||
|
||||
|
@ -57,10 +60,15 @@ internal sealed class DaprWorkflowClientBuilderFactory
|
|||
|
||||
if (!string.IsNullOrWhiteSpace(apiToken))
|
||||
{
|
||||
httpClient.DefaultRequestHeaders.Add( "Dapr-Api-Token", apiToken);
|
||||
httpClient.DefaultRequestHeaders.Add("Dapr-Api-Token", apiToken);
|
||||
}
|
||||
|
||||
builder.UseGrpc(GrpcChannel.ForAddress(grpcEndpoint, new GrpcChannelOptions { HttpClient = httpClient }));
|
||||
var channelOptions = options.GrpcChannelOptions ?? new GrpcChannelOptions
|
||||
{
|
||||
HttpClient = httpClient
|
||||
};
|
||||
|
||||
builder.UseGrpc(GrpcChannel.ForAddress(grpcEndpoint, channelOptions));
|
||||
builder.RegisterDirectly();
|
||||
});
|
||||
|
||||
|
@ -81,8 +89,12 @@ internal sealed class DaprWorkflowClientBuilderFactory
|
|||
httpClient.DefaultRequestHeaders.Add("Dapr-Api-Token", apiToken);
|
||||
}
|
||||
|
||||
builder.UseGrpc(
|
||||
GrpcChannel.ForAddress(grpcEndpoint, new GrpcChannelOptions { HttpClient = httpClient }));
|
||||
var channelOptions = options.GrpcChannelOptions ?? new GrpcChannelOptions
|
||||
{
|
||||
HttpClient = httpClient
|
||||
};
|
||||
|
||||
builder.UseGrpc(GrpcChannel.ForAddress(grpcEndpoint, channelOptions));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
using Grpc.Net.Client;
|
||||
|
||||
namespace Dapr.Workflow
|
||||
{
|
||||
using System;
|
||||
|
@ -29,6 +31,11 @@ namespace Dapr.Workflow
|
|||
/// </summary>
|
||||
readonly Dictionary<string, Action<DurableTaskRegistry>> factories = new();
|
||||
|
||||
/// <summary>
|
||||
/// Override GrpcChannelOptions.
|
||||
/// </summary>
|
||||
internal GrpcChannelOptions? GrpcChannelOptions { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="WorkflowRuntimeOptions"/> class.
|
||||
/// </summary>
|
||||
|
@ -118,6 +125,15 @@ namespace Dapr.Workflow
|
|||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Uses the provided <paramref name="grpcChannelOptions" /> for creating the <see cref="GrpcChannel" />.
|
||||
/// </summary>
|
||||
/// <param name="grpcChannelOptions">The <see cref="GrpcChannelOptions" /> to use for creating the <see cref="GrpcChannel" />.</param>
|
||||
public void UseGrpcChannelOptions(GrpcChannelOptions grpcChannelOptions)
|
||||
{
|
||||
this.GrpcChannelOptions = grpcChannelOptions;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method to add workflows and activities to the registry.
|
||||
/// </summary>
|
||||
|
|
|
@ -31,6 +31,7 @@ namespace Dapr.E2E.Test
|
|||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Serilog;
|
||||
using Grpc.Net.Client;
|
||||
|
||||
/// <summary>
|
||||
/// Startup class.
|
||||
|
@ -96,6 +97,25 @@ namespace Dapr.E2E.Test
|
|||
return Task.FromResult($"We are shipping {input} to the customer using our hoard of drones!");
|
||||
});
|
||||
});
|
||||
services.AddDaprWorkflow(options =>
|
||||
{
|
||||
// Example of registering a "StartOrder" workflow function
|
||||
options.RegisterWorkflow<string, string>("StartLargeOrder", implementation: async (context, input) =>
|
||||
{
|
||||
var itemToPurchase = input;
|
||||
itemToPurchase = await context.WaitForExternalEventAsync<string>("FinishLargeOrder");
|
||||
return itemToPurchase;
|
||||
});
|
||||
options.RegisterActivity<string, string>("FinishLargeOrder", implementation: (context, input) =>
|
||||
{
|
||||
return Task.FromResult($"We are finishing, it's huge!");
|
||||
});
|
||||
options.UseGrpcChannelOptions(new GrpcChannelOptions
|
||||
{
|
||||
MaxReceiveMessageSize = 32 * 1024 * 1024,
|
||||
MaxSendMessageSize = 32 * 1024 * 1024
|
||||
});
|
||||
});
|
||||
services.AddActors(options =>
|
||||
{
|
||||
options.UseJsonSerialization = JsonSerializationEnabled;
|
||||
|
|
|
@ -58,6 +58,7 @@ namespace Dapr.E2E.Test
|
|||
"--components-path", componentsPath,
|
||||
"--config", configPath,
|
||||
"--log-level", "debug",
|
||||
"--dapr-http-max-request-size", "32",
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue