abstract class GRPC::Service

Overview

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

Direct Known Subclasses

Defined in:

grpc/service_handler.cr

Instance Method Summary

Instance Method Detail

def 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).


[View source]
def 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).


[View source]
abstract def 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}.


[View source]
def 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.


[View source]
def 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.


[View source]
def 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.


[View source]
def 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).


[View source]
abstract def service_full_name : String #

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


[View source]