Documentation

Implement GRPC Services in Nomirun modules

Comes only with version Nomirun CLI and Nomirun Host 1.0.110 and above.

Grpc services are implemented the way you know it. The only difference is that you need to inherit your Grpc services from NomirunGrpcService class.

When you create a new module, the sample protobuf file and Grpc service are located in the src/Infrastructure/Grpc folder.

Here is an example of a proto file:

syntax = "proto3";

option csharp_namespace = "CustomerModule.Infrastructure.Grpc";

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;
  int32 a = 2;
  int32 b = 3;
}

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

And here is the service file:

using Grpc.Core;
using Microsoft.Extensions.Logging;
using Nomirun.Sdk.Abstractions.Interfaces;

namespace CustomerModule.Infrastructure.Grpc
{
    public class GreeterService : Greeter.GreeterBase, NomirunGrpcService
    {
        private readonly ILogger<GreeterService> _logger;

        public GreeterService(ILogger<GreeterService> logger)
        {
            _logger = logger;
        }

        public override Task<HelloReply> SayHello(HelloRequest request, ServerCallContext context)
        {
            _logger.LogInformation("Saying hello");
            return Task.FromResult(new HelloReply
            {
                Message = $"{request.Name} = {request.A + request.B}"
            });
        }
    }
}

The Grpc Service will be registered automatically when module is run by the Nomirun host. Service is exposed on the GrpcPort or GrpcsPort (read more here).