Open Closed

gRPC for abp micrservice project using webgateway #4715


User avatar
0
jeffbuot created
  • ABP Framework version: v7.0.3
  • DB provider: EF Core
  • Project Template: Microservice

Need help on how to implement grpc for a microservice solution. I followed the article here: https://community.abp.io/posts/using-grpc-with-the-abp-framework-2dgaxzw3 but this was for a single-layer application project.

We have multiple host services running and each have a different port for gRPC, how can I configure to forward them in the WebGateway project?


6 Answer(s)
  • User Avatar
    0
    gterdem created
    Senior .NET Developer

    We have eShopOnAbp sample demonstrates it that you can check. BasketService making gRPC request to CatalogService.

  • User Avatar
    0
    jeffbuot created

    Hi, I think it was not related to my case, basket service is just another service that acts as a client that requests to catalogservice. My question is related to gateway, I wanted the client to only call request into a single url or the url of webgateway proxy that routes the request to the grpc server hosts (these hosts are containerized and is inside a private network). The microservice service template project is using ocelot.

  • User Avatar
    0
    gterdem created
    Senior .NET Developer

    Hi,

    There is still an open issue about gRPC support for Ocelot however It may not be supported at all. We have an internal issue about changing the gateway library and we will try to hasten our discussion for a solution about this subject.

    Unfortunatelly we don't have a sample for the web or public-web application making a gRPC request through the gateway to a microservice. The gateway should have support for non-http protocol redirects. Maybe you can change ocelot to YARP and try it. There is a documentation about Proxying gRPC.

  • User Avatar
    0
    jeffbuot created

    Hi, Okay so I changed the gateway from Ocelot to Yarp but I have problems with authentication,

    Volo.Abp.Authorization.AbpAuthorizationException: Exception of type 'Volo.Abp.Authorization.AbpAuthorizationException' was thrown.
    
    if (Self._grpcChannel == null)
                {
                    var grpcOptions = Self._serviceProvider.GetRequiredService<IOptions<GrpcServiceOptions>>().Value;
                    var userAccount = Self._serviceProvider.GetRequiredService<UserAccountSessionManager>();
                    var token = userAccount.AccessTokenInfo.AccessToken;
                    var credentials = CallCredentials.FromInterceptor((context, metadata) =>
                    {
                        if (!string.IsNullOrEmpty(token))
                        {
                            metadata.Add("Authorization", $"Bearer {token}");
                        }
                        return Task.CompletedTask;
                    });
    
                    Self._grpcChannel = GrpcChannel.ForAddress(grpcOptions.GrpcServiceUri, new GrpcChannelOptions
                    {
                        Credentials = ChannelCredentials.Create(new SslCredentials(), credentials)
                    });
                }
                
                return Self._grpcChannel;
    
  • User Avatar
    0
    jeffbuot created

    Hi,

    This has been here week ago, we needed the grpc to be on the webgateway since we don't expose the microservices. Is there a backlog or a roadmap on abp dev team where we can possibly implement this later with abp?

  • User Avatar
    0
    gterdem created
    Senior .NET Developer

    Technically adding Authorization header with Bearer token should work as documented in https://learn.microsoft.com/en-us/aspnet/core/grpc/authn-and-authz?view=aspnetcore-7.0

    If you check with wireshark or similar tools, does your gRPC request to YARP contain this header? Can you pinpoint the exact problem if it is about the request to YARP or after the YARP? You may need to route the header manually perhaps https://microsoft.github.io/reverse-proxy/articles/header-routing.html

    I don't have a sample for this scenario unfortunatelly. I have it on backlog and check it whenever I find time.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 12, 2024, 07:15