GRPCClientPool Elixir

Hex.pm

A connection pooling library to be used along with grpc to create a connection pool of gRPC clients

Installation

The package can be installed with:

def deps do
[
{:grpc_client_pool, "~> 0.0.1-beta"}
]
end

Usage

  1. Follow grpc instructions on how to generate the elixir code
  2. Create a module in your app that will act as a client and make it use the connection pool:
defmodule MyApp.GRPCClient do
use GRPCClientPool,
otp_app: :my_app
end
  1. Configure the client:
config :my_app, MyApp.GRPCClient,
size: 2,
max_overflow: 10,
url: "localhost:50051,
connect_opts: []
  1. Add client requests within your new module:
defmodule MyApp.GRPCClient do
use GRPCClientPool,
otp_app: :my_app
alias GeneratedProto.ApiInput
alias GeneratedProto.ApiService.Stub
def remote_function(%ApiInput{} = params) do
with_channel(fn channel ->
Stub.remote_function(channel, params)
end)
end
end

Options

The available configuration parameters are:

NameDefaultRequiredDescription
size2falsePoolboy size parameter
max_overflow10falsePoolboy max_overflow parameter
urlniltrueThe url to be used as first argument of GRPC.Stub.connect/2. Can be either a string or {:system, "ENV"} or {:system, "ENV", "default"} to load the value from an env variable
connect_opts[]falseThe second argument passed to GRPC.Stub.connect/2

TODO