Giter Club home page Giter Club logo

grpc's Introduction

gRPC Elixir

Hex.pm Travis Status GitHub actions Status License Last Updated Total Download

An Elixir implementation of gRPC.

Table of contents

Notice

Note The Gun library doesn't have a full 2.0 release yet, so we depend on :grcp_gun 2.0.1 for now. This is the same as :gun 2.0.0-rc.2, but Hex doesn't let us depend on RC versions for releases.

Installation

The package can be installed as:

def deps do
  [
    {:grpc, "~> 0.5.0"},
    # We don't force protobuf as a dependency for more
    # flexibility on which protobuf library is used,
    # but you probably want to use it as well
    {:protobuf, "~> 0.11"}
  ]
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. Start the server

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

# Define your endpoint
defmodule Helloworld.Endpoint do
  use GRPC.Endpoint

  intercept GRPC.Server.Interceptors.Logger
  run Helloworld.Greeter.Server
end

# In the start function of your Application
defmodule HelloworldApp do
  use Application
  def start(_type, _args) do
    children = [
      # ...
      {GRPC.Server.Supervisor, endpoint: Helloworld.Endpoint, port: 50051}
    ]

    opts = [strategy: :one_for_one, name: YourApp]
    Supervisor.start_link(children, opts)
  end
end
  1. Call rpc:
iex> {:ok, channel} = GRPC.Stub.connect("localhost:50051")
iex> request = Helloworld.HelloRequest.new(name: "grpc-elixir")
iex> {:ok, reply} = channel |> Helloworld.Greeter.Stub.say_hello(request)

# With interceptors
iex> {:ok, channel} = GRPC.Stub.connect("localhost:50051", interceptors: [GRPC.Client.Interceptors.Logger])
...

Check examples and interop(Interoperability Test) for some examples.

Features

Benchmark

  1. Simple benchmark by using ghz

  2. Benchmark followed by official spec

Contributing

Your 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.

grpc's People

Contributors

adrielbento avatar angelo-moreira avatar asummers avatar avillen avatar beligante avatar cjab avatar d2km avatar darkofabijan avatar drowzy avatar falood avatar fire avatar htrefil avatar jayh5 avatar josevalim avatar nmashton avatar pettermachado avatar polvalente avatar rands0n avatar rbao avatar redink avatar scohen avatar shouya avatar sorliem avatar ssboisen avatar szahariev avatar tiagopog avatar tony612 avatar wingyplus avatar xenolf avatar zph avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.