Sandeep
Sandeep

Reputation: 1

Unable to access gRPC service though Yarp Gateway in .Net Core

I have created a gRPC service in Asp.net core Web API using nuget packages - Grpc.AspNetCore 2.57.0, Grpc.Tools 2.64.0, Google.Protobuf 3.27.2. I am able to access it successfully through my .Net Core Web application. However, when I try to access it through the Yarp Gateway, getting 404 error. Can someone please help me to get rid of this issue?

Exception Details : Grpc.Core.RpcException: Status(StatusCode="Unimplemented", Detail="Bad gRPC response. HTTP status code: 404")

gRPC service Proto file

syntax = "proto3";

option csharp_namespace = "GrpcService.CatalogAPI";

package CatalogGrpcService;

import "google/protobuf/empty.proto";

service CatalogGrpcAPI{
    rpc GetAllCatalogs (google.protobuf.Empty) returns (CatalogListResponse);    
}

// A Catalog resource.
message CatalogModel {
  string catalogId = 1;
  string name = 2;
  string description = 3;
  float price = 4;
}

// Response message to GetAllCatalogs method.
message CatalogListResponse {
    repeated CatalogModel catalogs = 1;
}

Aspnet Core Web Application client

//var grpcChannel = GrpcChannel.ForAddress("https://localhost:7005"); // Works well with this direct URL of the gRPC service
var grpcChannel = GrpcChannel.ForAddress("https://localhost:7700"); // Gives error with this https URL of Yarp Api Gateway
//var grpcChannel = GrpcChannel.ForAddress("http://localhost:5000"); // Gives error with this http URL of Yarp Api Gateway

var client = new CatalogGrpcAPI.CatalogGrpcAPIClient(grpcChannel);
var response = await client.GetAllCatalogsAsync(requestModel);

Yarp Gateway config

"Kestrel": {
  "Endpoints": {
    "http": {
      "Url": "http://localhost:5000",
      "Protocols": "Http2"
    },
    "https": {
      "Url": "https://localhost:7700"
    }
  }
},
"Yarp": {
  "Routes": {
    "catalog-route": {
      "ClusterId": "catalogCluster",
      "Match": {
        "Path": "/CatalogGrpcService.CatalogGrpcAPI/{**catch-all}"
      },
      "Transforms": [ { "PathPattern": "{**catch-all}" } ]
    }
  },
  "Clusters": {
    "catalogCluster": {
      "HttpRequest": {
        "Version": "2",
        "VersionPolicy": "RequestVersionExact"
      },
      "Destinations": {
        "catalogCluster/destination1": {
          "Address": "https://localhost:7005/"
        }
      }
    }
  }
}

Upvotes: 0

Views: 182

Answers (0)

Related Questions