Skip to content

Commit 215f904

Browse files
authored
Multi-target gRPC packages. Use protobuf directly (#98)
1 parent 8efb708 commit 215f904

28 files changed

+229
-185
lines changed

.editorconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
# Remove the line below if you want to inherit .editorconfig settings from higher directories
22
root = true
33

4+
# XML project files
5+
[*.{csproj,proj}]
6+
indent_size = 2
7+
indent_style = space
8+
9+
# XML config files
10+
[*.{props,targets,resx,nuspec,config,ruleset}]
11+
indent_size = 2
12+
indent_style = space
13+
414
# C# files
515
[*.cs]
616

.github/workflows/validate-build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ jobs:
1818

1919
steps:
2020
- uses: actions/checkout@v3
21+
with:
22+
submodules: true
2123

2224
- name: Setup .NET
2325
uses: actions/setup-dotnet@v3

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "eng/proto"]
2+
path = eng/proto
3+
url = https://github.com/microsoft/durabletask-protobuf

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- `DurableTaskClient` methods have been touched up to ensure `CancellationToken` is included, as well as is the last parameter.
99
- Removed obsolete/unimplemented local lambda activity calls from `TaskOrchestrationContext`
1010
- Input is now an optional parameter on `TaskOrchestrationContext.ContinueAsNew`
11+
- Multi-target gRPC projects to now use `Grpc.Net.Client` when appropriate (.NET6.0 and up)
1112

1213
## v1.0.0-rc.1
1314

Microsoft.DurableTask.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Shared", "src\Shared\Shared
5757
EndProject
5858
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "misc", "misc\misc.csproj", "{1E135970-60CF-470A-9270-4560BFA0A7DF}"
5959
EndProject
60+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Grpc", "src\Grpc\Grpc.csproj", "{44AD321D-96D4-481E-BD41-D0B12A619833}"
61+
EndProject
6062
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Benchmarks", "test\Benchmarks\Benchmarks.csproj", "{82C0CD7D-2764-421A-8256-7E2304D5A6E7}"
6163
EndProject
6264
Global
@@ -145,6 +147,10 @@ Global
145147
{1E135970-60CF-470A-9270-4560BFA0A7DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
146148
{1E135970-60CF-470A-9270-4560BFA0A7DF}.Release|Any CPU.ActiveCfg = Release|Any CPU
147149
{1E135970-60CF-470A-9270-4560BFA0A7DF}.Release|Any CPU.Build.0 = Release|Any CPU
150+
{44AD321D-96D4-481E-BD41-D0B12A619833}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
151+
{44AD321D-96D4-481E-BD41-D0B12A619833}.Debug|Any CPU.Build.0 = Debug|Any CPU
152+
{44AD321D-96D4-481E-BD41-D0B12A619833}.Release|Any CPU.ActiveCfg = Release|Any CPU
153+
{44AD321D-96D4-481E-BD41-D0B12A619833}.Release|Any CPU.Build.0 = Release|Any CPU
148154
{82C0CD7D-2764-421A-8256-7E2304D5A6E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
149155
{82C0CD7D-2764-421A-8256-7E2304D5A6E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
150156
{82C0CD7D-2764-421A-8256-7E2304D5A6E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -177,6 +183,7 @@ Global
177183
{8A0156E6-F033-49AB-AB0C-6698CE1DB24F} = {EFF7632B-821E-4CFC-B4A0-ED4B24296B17}
178184
{21AF0D71-6D32-483F-B6E8-3B28EE432560} = {EFF7632B-821E-4CFC-B4A0-ED4B24296B17}
179185
{57A4C812-B0D9-49E9-9EBE-7E94D3D78ED7} = {8AFC9781-F6F1-4696-BB4A-9ED7CA9D612B}
186+
{44AD321D-96D4-481E-BD41-D0B12A619833} = {8AFC9781-F6F1-4696-BB4A-9ED7CA9D612B}
180187
{82C0CD7D-2764-421A-8256-7E2304D5A6E7} = {E5637F81-2FB9-4CD7-900D-455363B142A7}
181188
EndGlobalSection
182189
GlobalSection(ExtensibilityGlobals) = postSolution

azure-pipelines-release.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ pool:
88
- ImageOverride -equals MMS2022TLS
99

1010
steps:
11+
- checkout: self
12+
submodules: true
13+
1114
- task: UseDotNet@2
1215
displayName: 'Use the .NET Core 2.1 SDK (required for build signing)'
1316
inputs:

eng/proto

Submodule proto added at 7d68268

src/Client/Grpc/Client.Grpc.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.0</TargetFramework>
4+
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
55
<PackageDescription>The gRPC client for the Durable Task Framework.</PackageDescription>
66
<EnableStyleCop>true</EnableStyleCop>
77
</PropertyGroup>
@@ -13,17 +13,18 @@
1313
</PropertyGroup>
1414

1515
<ItemGroup>
16-
<PackageReference Include="Microsoft.DurableTask.Sidecar.Protobuf" Version="1.0.0" />
1716
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
1817
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
1918
</ItemGroup>
2019

2120
<ItemGroup>
2221
<ProjectReference Include="../Core/Client.csproj" />
22+
<ProjectReference Include="../../Grpc/Grpc.csproj" />
2323
</ItemGroup>
2424

2525
<ItemGroup>
2626
<SharedSection Include="Core" />
27+
<SharedSection Include="Grpc" />
2728
</ItemGroup>
2829

2930
</Project>

src/Client/Grpc/DependencyInjection/DurableTaskClientBuilderExtensions.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
using Grpc.Core;
54
using Microsoft.DurableTask.Client.Grpc;
65
using Microsoft.Extensions.DependencyInjection;
76

@@ -44,7 +43,7 @@ public static IDurableTaskClientBuilder UseGrpc(this IDurableTaskClientBuilder b
4443
/// <param name="builder">The builder to configure.</param>
4544
/// <param name="channel">The channel for the Durable Task sidecar endpoint.</param>
4645
/// <returns>The original builder, for call chaining.</returns>
47-
public static IDurableTaskClientBuilder UseGrpc(this IDurableTaskClientBuilder builder, Channel channel)
46+
public static IDurableTaskClientBuilder UseGrpc(this IDurableTaskClientBuilder builder, GrpcChannel channel)
4847
=> builder.UseGrpc(opt => opt.Channel = channel);
4948

5049
/// <summary>

src/Client/Grpc/GrpcDurableTaskClient.cs

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public sealed class GrpcDurableTaskClient : DurableTaskClient
2020
readonly ILogger logger;
2121
readonly TaskHubSidecarServiceClient sidecarClient;
2222
readonly GrpcDurableTaskClientOptions options;
23-
readonly AsyncDisposable asyncDisposable;
23+
AsyncDisposable asyncDisposable;
2424

2525
/// <summary>
2626
/// Initializes a new instance of the <see cref="GrpcDurableTaskClient"/> class.
@@ -46,7 +46,7 @@ public GrpcDurableTaskClient(string name, GrpcDurableTaskClientOptions options,
4646
{
4747
this.logger = Check.NotNull(logger);
4848
this.options = Check.NotNull(options);
49-
this.asyncDisposable = this.BuildChannel(out Channel channel);
49+
this.asyncDisposable = BuildChannel(options, out GrpcChannel channel);
5050
this.sidecarClient = new TaskHubSidecarServiceClient(channel);
5151
}
5252

@@ -336,6 +336,43 @@ public override Task<PurgeResult> PurgeInstancesAsync(
336336
return this.PurgeInstancesCoreAsync(request, cancellation);
337337
}
338338

339+
static AsyncDisposable BuildChannel(GrpcDurableTaskClientOptions options, out GrpcChannel channel)
340+
{
341+
if (options.Channel is GrpcChannel c)
342+
{
343+
channel = c;
344+
return default;
345+
}
346+
347+
c = GetChannel(options.Address);
348+
channel = c;
349+
return new AsyncDisposable(async () => await c.ShutdownAsync());
350+
}
351+
352+
#if NET6_0_OR_GREATER
353+
static GrpcChannel GetChannel(string? address)
354+
{
355+
if (string.IsNullOrEmpty(address))
356+
{
357+
address = "http://localhost:4001";
358+
}
359+
360+
return GrpcChannel.ForAddress(address);
361+
}
362+
#endif
363+
364+
#if NETSTANDARD2_0
365+
static GrpcChannel GetChannel(string? address)
366+
{
367+
if (string.IsNullOrEmpty(address))
368+
{
369+
address = "localhost:4001";
370+
}
371+
372+
return new(address, ChannelCredentials.Insecure);
373+
}
374+
#endif
375+
339376
async Task<PurgeResult> PurgeInstancesCoreAsync(
340377
P.PurgeInstancesRequest request, CancellationToken cancellation = default)
341378
{
@@ -362,24 +399,8 @@ OrchestrationMetadata CreateMetadata(P.OrchestrationState state, bool includeInp
362399
SerializedInput = state.Input,
363400
SerializedOutput = state.Output,
364401
SerializedCustomStatus = state.CustomStatus,
365-
FailureDetails = ProtoUtils.ConvertTaskFailureDetails(state.FailureDetails),
402+
FailureDetails = state.FailureDetails.ToTaskFailureDetails(),
366403
DataConverter = includeInputsAndOutputs ? this.DataConverter : null,
367404
};
368405
}
369-
370-
AsyncDisposable BuildChannel(out Channel channel)
371-
{
372-
if (this.options.Channel is Channel c)
373-
{
374-
channel = c;
375-
return default;
376-
}
377-
378-
string address = string.IsNullOrEmpty(this.options.Address) ? "localhost:4001" : this.options.Address!;
379-
380-
// TODO: use SSL channel by default?
381-
c = new(address, ChannelCredentials.Insecure);
382-
channel = c;
383-
return new AsyncDisposable(async () => await c.ShutdownAsync());
384-
}
385406
}

0 commit comments

Comments
 (0)