Skip to content

Commit a06605c

Browse files
humandigital-ruudhumandigital-michiel
authored andcommitted
Refactor DaprWorkflowClientBuilderFactory and WorkflowRuntimeOptions (dapr#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 <[email protected]> Co-authored-by: Michiel van Praat <[email protected]> Signed-off-by: Siri Varma Vegiraju <[email protected]>
1 parent d1aa92b commit a06605c

File tree

4 files changed

+55
-6
lines changed

4 files changed

+55
-6
lines changed

src/Dapr.Workflow/DaprWorkflowClientBuilderFactory.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public DaprWorkflowClientBuilderFactory(IConfiguration configuration, IHttpClien
4141
_httpClientFactory = httpClientFactory;
4242
_services = services;
4343
}
44-
44+
4545
/// <summary>
4646
/// Responsible for building the client itself.
4747
/// </summary>
@@ -50,17 +50,25 @@ public void CreateClientBuilder(Action<WorkflowRuntimeOptions> configure)
5050
{
5151
_services.AddDurableTaskClient(builder =>
5252
{
53+
WorkflowRuntimeOptions options = new();
54+
configure?.Invoke(options);
55+
5356
var apiToken = DaprDefaults.GetDefaultDaprApiToken(_configuration);
5457
var grpcEndpoint = DaprDefaults.GetDefaultGrpcEndpoint(_configuration);
55-
58+
5659
var httpClient = _httpClientFactory.CreateClient();
5760

5861
if (!string.IsNullOrWhiteSpace(apiToken))
5962
{
60-
httpClient.DefaultRequestHeaders.Add( "Dapr-Api-Token", apiToken);
63+
httpClient.DefaultRequestHeaders.Add("Dapr-Api-Token", apiToken);
6164
}
6265

63-
builder.UseGrpc(GrpcChannel.ForAddress(grpcEndpoint, new GrpcChannelOptions { HttpClient = httpClient }));
66+
var channelOptions = options.GrpcChannelOptions ?? new GrpcChannelOptions
67+
{
68+
HttpClient = httpClient
69+
};
70+
71+
builder.UseGrpc(GrpcChannel.ForAddress(grpcEndpoint, channelOptions));
6472
builder.RegisterDirectly();
6573
});
6674

@@ -81,8 +89,12 @@ public void CreateClientBuilder(Action<WorkflowRuntimeOptions> configure)
8189
httpClient.DefaultRequestHeaders.Add("Dapr-Api-Token", apiToken);
8290
}
8391

84-
builder.UseGrpc(
85-
GrpcChannel.ForAddress(grpcEndpoint, new GrpcChannelOptions { HttpClient = httpClient }));
92+
var channelOptions = options.GrpcChannelOptions ?? new GrpcChannelOptions
93+
{
94+
HttpClient = httpClient
95+
};
96+
97+
builder.UseGrpc(GrpcChannel.ForAddress(grpcEndpoint, channelOptions));
8698
}
8799
else
88100
{

src/Dapr.Workflow/WorkflowRuntimeOptions.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
// limitations under the License.
1212
// ------------------------------------------------------------------------
1313

14+
using Grpc.Net.Client;
15+
1416
namespace Dapr.Workflow
1517
{
1618
using System;
@@ -29,6 +31,11 @@ public sealed class WorkflowRuntimeOptions
2931
/// </summary>
3032
readonly Dictionary<string, Action<DurableTaskRegistry>> factories = new();
3133

34+
/// <summary>
35+
/// Override GrpcChannelOptions.
36+
/// </summary>
37+
internal GrpcChannelOptions? GrpcChannelOptions { get; private set; }
38+
3239
/// <summary>
3340
/// Initializes a new instance of the <see cref="WorkflowRuntimeOptions"/> class.
3441
/// </summary>
@@ -117,6 +124,15 @@ public void RegisterActivity<TActivity>() where TActivity : class, IWorkflowActi
117124
WorkflowLoggingService.LogActivityName(name);
118125
});
119126
}
127+
128+
/// <summary>
129+
/// Uses the provided <paramref name="grpcChannelOptions" /> for creating the <see cref="GrpcChannel" />.
130+
/// </summary>
131+
/// <param name="grpcChannelOptions">The <see cref="GrpcChannelOptions" /> to use for creating the <see cref="GrpcChannel" />.</param>
132+
public void UseGrpcChannelOptions(GrpcChannelOptions grpcChannelOptions)
133+
{
134+
this.GrpcChannelOptions = grpcChannelOptions;
135+
}
120136

121137
/// <summary>
122138
/// Method to add workflows and activities to the registry.

test/Dapr.E2E.Test.App/Startup.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ namespace Dapr.E2E.Test
3131
using System.Threading.Tasks;
3232
using Microsoft.Extensions.Logging;
3333
using Serilog;
34+
using Grpc.Net.Client;
3435

3536
/// <summary>
3637
/// Startup class.
@@ -96,6 +97,25 @@ public void ConfigureServices(IServiceCollection services)
9697
return Task.FromResult($"We are shipping {input} to the customer using our hoard of drones!");
9798
});
9899
});
100+
services.AddDaprWorkflow(options =>
101+
{
102+
// Example of registering a "StartOrder" workflow function
103+
options.RegisterWorkflow<string, string>("StartLargeOrder", implementation: async (context, input) =>
104+
{
105+
var itemToPurchase = input;
106+
itemToPurchase = await context.WaitForExternalEventAsync<string>("FinishLargeOrder");
107+
return itemToPurchase;
108+
});
109+
options.RegisterActivity<string, string>("FinishLargeOrder", implementation: (context, input) =>
110+
{
111+
return Task.FromResult($"We are finishing, it's huge!");
112+
});
113+
options.UseGrpcChannelOptions(new GrpcChannelOptions
114+
{
115+
MaxReceiveMessageSize = 32 * 1024 * 1024,
116+
MaxSendMessageSize = 32 * 1024 * 1024
117+
});
118+
});
99119
services.AddActors(options =>
100120
{
101121
options.UseJsonSerialization = JsonSerializationEnabled;

test/Dapr.E2E.Test/DaprTestApp.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public DaprTestApp(ITestOutputHelper output, string appId)
5858
"--components-path", componentsPath,
5959
"--config", configPath,
6060
"--log-level", "debug",
61+
"--dapr-http-max-request-size", "32",
6162

6263
};
6364

0 commit comments

Comments
 (0)