Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option to override GrpcChannelOptions when adding DaprWorkflow (#7218) #1244

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions src/Dapr.Workflow/DaprWorkflowClientBuilderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public DaprWorkflowClientBuilderFactory(IConfiguration configuration, IHttpClien
_httpClientFactory = httpClientFactory;
_services = services;
}

/// <summary>
/// Responsible for building the client itself.
/// </summary>
Expand All @@ -50,17 +50,25 @@ public void CreateClientBuilder(Action<WorkflowRuntimeOptions> configure)
{
_services.AddDurableTaskClient(builder =>
{
WorkflowRuntimeOptions options = new();
configure?.Invoke(options);

var apiToken = DaprDefaults.GetDefaultDaprApiToken(_configuration);
var grpcEndpoint = DaprDefaults.GetDefaultGrpcEndpoint(_configuration);

var httpClient = _httpClientFactory.CreateClient();

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

Expand All @@ -81,8 +89,12 @@ public void CreateClientBuilder(Action<WorkflowRuntimeOptions> configure)
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
{
Expand Down
16 changes: 16 additions & 0 deletions src/Dapr.Workflow/WorkflowRuntimeOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
// limitations under the License.
// ------------------------------------------------------------------------

using Grpc.Net.Client;

namespace Dapr.Workflow
{
using System;
Expand All @@ -29,6 +31,11 @@ public sealed class WorkflowRuntimeOptions
/// </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>
Expand Down Expand Up @@ -117,6 +124,15 @@ public void RegisterActivity<TActivity>() where TActivity : class, IWorkflowActi
WorkflowLoggingService.LogActivityName(name);
});
}

/// <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.
Expand Down
20 changes: 20 additions & 0 deletions test/Dapr.E2E.Test.App/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace Dapr.E2E.Test
using System;
using Microsoft.Extensions.Logging;
using Serilog;
using Grpc.Net.Client;

/// <summary>
/// Startup class.
Expand Down Expand Up @@ -98,6 +99,25 @@ public void ConfigureServices(IServiceCollection services)
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;
Expand Down
1 change: 1 addition & 0 deletions test/Dapr.E2E.Test/DaprTestApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public DaprTestApp(ITestOutputHelper output, string appId)
"--components-path", componentsPath,
"--config", configPath,
"--log-level", "debug",
"--dapr-http-max-request-size", "32",

};

Expand Down
Loading