0

Cannot forward to 2 grpcservice with the same name using yarp.proxy.

I created two grpc services in two different projects in asp.net core and one project as my gateaway using yarp.proxy, in addition the two projects contain each 1 grpc service name greeter... Now cannot forward request to each one because I cannot figure out how to configure yarp configuration for this case. Any help?

he´s my proto files

grpc service 1
syntax = "proto3";

option csharp_namespace = "GrpcService1";

package greet;

// The greeting service definition.
service Greeter {
  // Sends a greeting
  rpc SayHello (HelloRequest) returns (HelloReply);
}

// The request message containing the user's name.
message HelloRequest {
  string name = 1;
}

// The response message containing the greetings.
message HelloReply {
  string message = 1;
}


Grpc service 2
syntax = "proto3";

option csharp_namespace = "GrpcService2";

package greet;

// The greeting service definition.
service Greeter {
  // Sends a greeting
  rpc SayHello (HelloRequest) returns (HelloReply);
}

// The request message containing the user's name.
message HelloRequest {
  string name = 1;
}

// The response message containing the greetings.
message HelloReply {
  string message = 1;
}

he´s how i´m calling the services

var channel1 = GrpcChannel.ForAddress("https://localhost:8000/greeter1/");
var client1 = new GrpcService1.Greeter.GreeterClient(channel1);
var request1 = new GrpcService1.HelloRequest { Name = "Jose Felix from service 1" };
var response1 = client1.SayHello(request1);

Console.WriteLine(response1.Message);

var channel2 = GrpcChannel.ForAddress("https://localhost:8000/service2");
var client2 = new GrpcService2.Greeter.GreeterClient(channel2);
var request2 = new GrpcService2.HelloRequest { Name = "Jose Felix from service 2" };
var response2 = client2.SayHello(request2);
Console.WriteLine(response2.Message);

I have tried this configuration without any success.

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*",
  "ReverseProxy": {
    "Routes": {
      "grpcservice1": {
        "ClusterId": "grpcservice1",
        "Match": {
          "Path": "/greeter/{**catch-all}"
        },
        "Transforms": [
          { "PathPattern": "/Greeter/{**catch-all}" }
        ]
      },
      "grpcservice2": {
        "ClusterId": "grpcservice2",
        "Match": {
          "Path": "service2/{**catch-all}"
        },
        "Transforms": [
          { "PathPattern": "{**catch-all}" }
        ]
      }
    },
    "Clusters": {
      "grpcservice1": {
        "HttpRequest": {
          "Version": "2",
          "VersionPolicy": "RequestVersionExact"
        },
        "Destinations": {
          "destination1": {
            "Address": "https://localhost:8001"
          }
        }
      },
      "grpcservice2": {
        "HttpRequest": {
          "Version": "2",
          "VersionPolicy": "RequestVersionExact"
        },
        "Destinations": {
          "destination1": {
            "Address": "https://localhost:8002"
          }
        }
      }
    }
  }
}
  • hi, after digging for a while (two days) I found out this article https://learn.microsoft.com/en-us/aspnet/core/grpc/troubleshoot?view=aspnetcore-7.0#calling-grpc-services-hosted-in-a-sub-directory and this discussion grpc/grpc-dotnet#880... I just solved my problem... I hope anyone finding this issue should be pointed to this solution much quicker than me – user1378816 May 25 '23 at 12:36

0 Answers0