Skip to content

Commit df783b3

Browse files
committed
Switch from Grpc.Core to Grpc.Net.Client (#758)
* Upgraded protobuf versions and removed Grpc.Core dependency * Updated channel and option types used * Change channel credentials * Added http prefix to url * Add valid URL check and explicitly include credentials
1 parent 6626477 commit df783b3

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/Messaging/MessagingStream.cs

+14-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Threading.Tasks;
99

1010
using Grpc.Core;
11+
using Grpc.Net.Client;
1112
using Microsoft.Azure.WebJobs.Script.Grpc.Messages;
1213

1314
namespace Microsoft.Azure.Functions.PowerShellWorker.Messaging
@@ -19,15 +20,24 @@ internal class MessagingStream
1920

2021
internal MessagingStream(string host, int port)
2122
{
23+
// To call unsecured gRPC services, ensure the address starts with 'http' as opposed to 'https'.
24+
// For more detail, see https://docs.microsoft.com/en-us/aspnet/core/grpc/client?view=aspnetcore-6.0
25+
string uriString = $"http://{host}:{port}";
26+
if (!Uri.TryCreate(uriString, UriKind.Absolute, out Uri grpcUri))
27+
{
28+
throw new InvalidOperationException($"The gRPC channel URI '{uriString}' could not be parsed.");
29+
}
30+
2231
const int maxMessageLength = int.MaxValue;
2332

24-
var channelOptions = new []
33+
var channelOptions = new GrpcChannelOptions
2534
{
26-
new ChannelOption(ChannelOptions.MaxReceiveMessageLength, maxMessageLength),
27-
new ChannelOption(ChannelOptions.MaxSendMessageLength, maxMessageLength)
35+
MaxReceiveMessageSize = maxMessageLength,
36+
MaxSendMessageSize = maxMessageLength,
37+
Credentials = ChannelCredentials.Insecure
2838
};
2939

30-
Channel channel = new Channel(host, port, ChannelCredentials.Insecure, channelOptions);
40+
GrpcChannel channel = GrpcChannel.ForAddress(grpcUri, channelOptions);
3141
_call = new FunctionRpc.FunctionRpcClient(channel).EventStream();
3242
}
3343

src/Microsoft.Azure.Functions.PowerShellWorker.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Licensed under the MIT license. See LICENSE file in the project root for full li
2020
</PropertyGroup>
2121

2222
<ItemGroup>
23-
<PackageReference Include="Grpc.Core" Version="2.27.0" />
23+
<PackageReference Include="Grpc.Core" Version="2.42.0" />
2424
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.0.8" />
2525
<PackageReference Include="CommandLineParser" Version="2.3.0" />
2626
<PackageReference Include="Google.Protobuf" Version="3.19.4" />

0 commit comments

Comments
 (0)