Skip to content
GRPC client and server builder for simplifying the code
Elixir Makefile Shell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.makefiles
lib fix stub generator Aug 8, 2019
test make the grpc builder work for general purpose. Aug 7, 2019
.credo.exs
.dialyzer_ignore.exs
.elixir_version init project Aug 7, 2019
.formatter.exs init project Aug 7, 2019
.gitignore
.pre-commit init project Aug 7, 2019
.travis.yml update travis Aug 7, 2019
CHANGELOG.md fix stub generator Aug 8, 2019
LICENSE
Makefile make the grpc builder work for general purpose. Aug 7, 2019
README.md add initial doc Aug 7, 2019
mix.exs
mix.lock init project Aug 7, 2019
version

README.md

GrpcBuilder

Generate GRPC client and server code.

Installation

def deps do
  [
    {:grpc_builder, "~> 0.1.0"}
  ]
end

Usage

In your GRPC client SDK application code, add GrpcBuilder.Client.ConnSupervisor into the children:

defmodule YourSdk.Application do
  @moduledoc false

  use Application
  alias GrpcBuilder.Client.ConnSupervisor

  def start(_type, _args) do
    children = [
      {ConnSupervisor, strategy: :one_for_one, name: ConnSupervisor}
    ]

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

Add your RPC definitions like this:

defmodule YourSdk.Rpc do
  @moduledoc """
  RPC client definition
  """
  import GrpcBuilder.Client.Builder, only: [rpc: 2, rpc: 3]

  # here the `res` is the response GRPC server returned to you. You can write code to process the response here.
  rpc :get_job, prefix: YourProtoAbi, do: res.job
end

You also need to define a Stub:

defmodule GrpcBuilder.Client.Stub do
  use GrpcBuilder.Client.StubGen, services: %{
    get_job: YourProtoAbi.GrpcService.Stub
  }
end

That's it! Then you can use your SDK like this:

GrpcBuilder.Client.connect("tcp://127.0.0.1:12345", name: "your_conn_name", default: true)
YourSdk.Rpc.get_job(request) # this is to use the default connection
YourSdk.Rpc.get_job(request, "your_conn_name") # this is the same as previous call
You can’t perform that action at this time.