Skip to content

Commit

Permalink
Switch from Grpc.Core to Grpc.Net.Client (#758)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
michaelpeng36 committed Feb 22, 2022
1 parent 6626477 commit df783b3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
18 changes: 14 additions & 4 deletions src/Messaging/MessagingStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading.Tasks;

using Grpc.Core;
using Grpc.Net.Client;
using Microsoft.Azure.WebJobs.Script.Grpc.Messages;

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

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

const int maxMessageLength = int.MaxValue;

var channelOptions = new []
var channelOptions = new GrpcChannelOptions
{
new ChannelOption(ChannelOptions.MaxReceiveMessageLength, maxMessageLength),
new ChannelOption(ChannelOptions.MaxSendMessageLength, maxMessageLength)
MaxReceiveMessageSize = maxMessageLength,
MaxSendMessageSize = maxMessageLength,
Credentials = ChannelCredentials.Insecure
};

Channel channel = new Channel(host, port, ChannelCredentials.Insecure, channelOptions);
GrpcChannel channel = GrpcChannel.ForAddress(grpcUri, channelOptions);
_call = new FunctionRpc.FunctionRpcClient(channel).EventStream();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Azure.Functions.PowerShellWorker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Licensed under the MIT license. See LICENSE file in the project root for full li
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Grpc.Core" Version="2.27.0" />
<PackageReference Include="Grpc.Core" Version="2.42.0" />
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.0.8" />
<PackageReference Include="CommandLineParser" Version="2.3.0" />
<PackageReference Include="Google.Protobuf" Version="3.19.4" />
Expand Down

0 comments on commit df783b3

Please sign in to comment.