GRPC.Service (gRPC Core v1.0.1)

Copy Markdown View Source

Define gRPC service used by Stub and Server. You should use Protobuf to to generate code instead of using this module directly.

It imports DSL functions like rpc/4 and stream/1 for defining the RPC functions easily:

defmodule Greeter.Service do
  use GRPC.Service, name: "helloworld.Greeter"

  rpc :SayHello, HelloRequest, stream(HelloReply)
end

option (google.api.http) annotations are supported for gRPC http/json transcoding. Once generated the 4th argument to rpc/4 contains the Google.Api.HttpRule option.

defmodule Greeter.Service do
  use GRPC.Service, name: "helloworld.Greeter"

  rpc(:SayHello, Helloworld.HelloRequest, Helloworld.HelloReply, %{
    http: %{
      type: Google.Api.PbExtension,
      value: %Google.Api.HttpRule{
        __unknown_fields__: [],
        additional_bindings: [],
        body: "",
        pattern: {:get, "/v1/greeter/{name}"},
        response_body: "",
        selector: ""
      }
    }
  })
end

Summary

Functions

Format the function name for display/logging purposes.

Specify if the request/reply is streaming.

Functions

format_function_name(rpc)

Format the function name for display/logging purposes.

If there's a name collision, returns "call(:Name, ...)" format to reflect actual usage. Otherwise, returns the underscored name.

Handles both full 4-element RPC tuples and partial tuples (for testing).

grpc_type(arg)

rpc(name, request, reply, options \\ quote do %{} end)

(macro)

rpc_options(arg)

rpc_options(arg, type)

stream(param)

Specify if the request/reply is streaming.