View Source Overview

ConnGRPC allows you to keep persistent channels, and use channel pools with gRPC Elixir.

installation

Installation

Add conn_grpc to your list of dependencies:

def deps do
  [
    {:conn_grpc, "~> 0.1"},

    # You also need to have gRPC Elixir installed
    {:grpc, "~> 0.5"}
  ]
end

usage

Usage

You can use ConnGRPC with a pool of persistent channels, or with a single persistent channel.

channel-pools

Channel pools

Define a module that uses ConnGRPC.Pool.

defmodule DemoPool do
  use ConnGRPC.Pool,
    pool_size: 5,
    channel: [address: "localhost:50051", opts: []]
end

Then add DemoPool to your supervision tree, and call get_channel/0 from anywhere in your application to get a channel connection:

{:ok, channel} = DemoPool.get_channel()

Each time get_channel is called, a different channel from your pool will be returned using round-robin distribution.

For more info, see ConnGRPC.Pool.

single-channel

Single channel

For a single persistent channel, define a module that uses ConnGRPC.Channel.

defmodule DemoChannel do
  use ConnGRPC.Channel, address: "localhost:50051", opts: []
end

Then add DemoChannel to your supervision tree, and call get/0 from anywhere in your application to get your channel connection:

{:ok, channel} = DemoChannel.get()

Depending on the load, using a single channel for the entire application may become a bottleneck. In that case, use the ConnGRPC.Pool module, that creates a pool of channels.

For more info, see ConnGRPC.Channel.