class

GRPC::Service

Inherits Reference < Object

Service is the abstract base class for gRPC service implementations. Generated service base classes inherit from this.

Users implement the generated abstract subclass, not this class directly.

Example (generated code): module Helloworld abstract class GreeterService < GRPC::Service SERVICE_FULL_NAME = "helloworld.Greeter"

  def service_full_name : String
    SERVICE_FULL_NAME
  end

  abstract def say_hello(req : HelloRequest, ctx : GRPC::ServerContext) : HelloReply

  def dispatch(method : String, body : Bytes, ctx : GRPC::ServerContext) : {Bytes, GRPC::Status}
    case method
    when "SayHello"
      req  = HelloRequest.decode(body)
      resp = say_hello(req, ctx)
      {resp.encode, GRPC::Status.ok}
    else
      {Bytes.empty, GRPC::Status.unimplemented("method #{method} not found")}
    end
  rescue ex : GRPC::StatusError
    {Bytes.empty, ex.status}
  rescue ex
    {Bytes.empty, GRPC::Status.internal(ex.message || "internal error")}
  end
end

end

Instance methods

bidi_streaming?(method : String) : Bool

bidi_streaming? returns true if method is a bidirectional streaming RPC. Generated service base classes override this; the default is false (unary).

Source
client_streaming?(method : String) : Bool

client_streaming? returns true if method is a client-streaming RPC. Generated service base classes override this; the default is false (unary).

Source
dispatch(method : String, request_body : Bytes, ctx : ServerContext) : Tuple(Bytes, Status)

dispatch routes an incoming unary RPC call to the correct method implementation. Returns {response_body : Bytes, status : Status}.

Source
dispatch_bidi_stream(method : String, requests : RawRequestStream, ctx : ServerContext, writer : RawResponseStream) : Status

dispatch_bidi_stream dispatches a bidirectional streaming RPC. requests is a RawRequestStream that yields raw message bytes as they arrive. The transport passes a RawResponseStream; generated subclasses wrap it in a typed ResponseStream(T) before handing off to the user implementation.

Source
dispatch_client_stream(method : String, requests : RawRequestStream, ctx : ServerContext) : Tuple(Bytes, Status)

dispatch_client_stream dispatches a client-streaming RPC. requests is a RawRequestStream that yields raw message bytes as they arrive. Returns {response_body : Bytes, status : Status}. Generated service base classes override this; the default returns UNIMPLEMENTED.

Source
dispatch_server_stream(method : String, request_body : Bytes, ctx : ServerContext, writer : RawResponseStream) : Status

dispatch_server_stream dispatches a server-streaming RPC. The transport passes a RawResponseStream; generated subclasses wrap it in a typed ResponseStream(T) before handing off to the user implementation.

Source
server_streaming?(method : String) : Bool

server_streaming? returns true if method is a server-streaming RPC. Generated service base classes override this; the default is false (unary).

Source
service_full_name

service_full_name returns the full gRPC service name (e.g. "helloworld.Greeter").

Source