Skip to content
middlewares
Switch branches/tags
Code
This branch is 17 commits ahead, 233 commits behind elixir-grpc:master.
Contribute

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
lib
 
 
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

gRPC Elixir

Build Status Inline docs

The Elixir implementation of gRPC.

WARNING: APIs are unstable now. Be careful to use it in production!

Installation

The package can be installed as:

  1. Add grpc to your list of dependencies in mix.exs:

    def deps do
      [{:grpc, github: "tony612/grpc-elixir"}]
    end
  2. Ensure grpc is started before your application:

    def application do
     [applications: [:grpc]]
    end

Usage

  1. Generate Elixir code from proto file as protobuf-elixir shows(especially the gRPC Support section).
  2. Implement the server side code like below and remember to return the expected message types.
defmodule Helloworld.Greeter.Server do
  use GRPC.Server, service: Helloworld.Greeter.Service

  @spec say_hello(Helloworld.HelloRequest.t, GRPC.Server.Stream.t) :: Helloworld.HelloReply.t
  def say_hello(request, _stream) do
    Helloworld.HelloReply.new(message: "Hello #{request.name}")
  end
end
  1. Run the server and client like this:
iex> GRPC.Server.start(Helloworld.Greeter.Server, 50051)
iex> {:ok, channel} = GRPC.Stub.connect("localhost:50051")
iex> request = Helloworld.HelloRequest.new(name: "grpc-elixir")
iex> channel |> Helloworld.Greeter.Stub.say_hello(request)

Start the server

You can start the gRPC server as a supervised process. First, add GRPC.Server.Supervisor to your supervision tree.

# In the start function of your Application
def start(_type, _args) do
  children = [
    # ...
    supervisor(GRPC.Server.Supervisor, [{Helloworld.Greeter.Server, 50051}])
  ]

  opts = [strategy: :one_for_one, name: YourApp]
  Supervisor.start_link(children, opts)
end

Then run grpc.server using a mix task

$ mix grpc.server

or start it when starting your application:

# config.exs
config :grpc, start_server: true

$ iex -S mix

Check examples for all examples

TODO

  • Unary RPC
  • Server streaming RPC
  • Client streaming RPC
  • Bidirectional streaming RPC
  • Helloworld and RouteGuide examples
  • Doc and more tests
  • Authentication with TLS
  • Improve code generation from protos (protobuf-elixir #8)
  • Improve timeout(now there's simple timeout)
  • Errors handling
  • Data compression
  • Benchmarking
  • Logging
  • Middleware support
    • Server
      • Unary
      • Streaming
        • send
        • recv
    • Client
      • Unary
      • Streaming
        • send
        • recv

Contributing

You contributions are welcome!

Please open issues if you have questions, problems and ideas. You can create pull requests directly if you want to fix little bugs, add small features and so on. But you'd better use issues first if you want to add a big feature or change a lot of code.

About

The Elixir implementation of gRPC

Resources

License

Packages

No packages published