Skip to content

Commit

Permalink
Improved the handling of the gRPC channel options.
Browse files Browse the repository at this point in the history
Signed-off-by: Michiel van Praat <michiel.vanpraat@humandigital.nl>
  • Loading branch information
humandigital-michiel committed Oct 23, 2024
1 parent a24b49c commit d9bba92
Showing 1 changed file with 18 additions and 6 deletions.
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

0 comments on commit d9bba92

Please sign in to comment.