grpc v0.5.0-beta.1 GRPC.Server View Source

A gRPC server which handles requests by calling user-defined functions.

You should pass a GRPC.Service in when use the module:

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

  rpc :SayHello, Request, Reply
  rpc :SayGoodbye, stream(Request), stream(Reply)
end

defmodule Greeter.Server do
  use GRPC.Server, service: Greeter.Service

  def say_hello(request, _stream) do
    Reply.new(message: "Hello")
  end

  def say_goodbye(request_enum, stream) do
    requests = Enum.map request_enum, &(&1)
    GRPC.Server.send_reply(stream, reply1)
    GRPC.Server.send_reply(stream, reply2)
  end
end

Your functions should accept a client request and a GRPC.Server.Stream. The request will be a Enumerable.t(created by Elixir's Stream) of requests if it's streaming. If a reply is streaming, you need to call send_reply/2 to send replies one by one instead of returning reply in the end.

Link to this section Summary

Functions

Send custom metadata(headers).

Set compressor to compress responses. An accepted compressor will be set if clients use one, even if set_compressor is not called. But this can be called to override the chosen.

Set custom metadata(headers).

Set custom trailers, which will be sent in the end.

DEPRECATED. Use send_reply/3 instead

Link to this section Types

Link to this type

rpc_return()

View Source
rpc_return() :: struct() | any()
Link to this type

servers_list()

View Source
servers_list() :: module() | [module()]
Link to this type

servers_map()

View Source
servers_map() :: %{required(String.t()) => [module()]}

Link to this section Functions

Link to this function

send_headers(stream, headers)

View Source

Send custom metadata(headers).

You can send headers only once, before that you can set headers using set_headers/2.

Link to this function

send_reply(stream, reply, opts \\ [])

View Source

Send streaming reply.

Examples

iex> GRPC.Server.send_reply(stream, reply)
Link to this function

set_compressor(stream, compressor)

View Source

Set compressor to compress responses. An accepted compressor will be set if clients use one, even if set_compressor is not called. But this can be called to override the chosen.

Link to this function

set_headers(stream, headers)

View Source

Set custom metadata(headers).

You can set headers more than once.

Link to this function

set_trailers(stream, trailers)

View Source

Set custom trailers, which will be sent in the end.

Link to this function

stream_send(stream, reply)

View Source
This function is deprecated. Use send_reply/3 instead.

DEPRECATED. Use send_reply/3 instead