Skip to content

Latest commit

 

History

History
77 lines (50 loc) · 2.25 KB

README.md

File metadata and controls

77 lines (50 loc) · 2.25 KB

Tests Contributor Covenant

ConnGRPC

Persistent channels, and channel pools for gRPC Elixir.

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

How to use

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

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 on Hexdocs.

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 on Hexdocs.

Code of Conduct

This project uses Contributor Covenant version 2.1. Check CODE_OF_CONDUCT.md file for more information.

License

ConnGRPC source code is released under Apache License 2.0.

Check NOTICE and LICENSE files for more information.