Code Monkey home page Code Monkey logo

conn_grpc's Introduction

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.

conn_grpc's People

Contributors

guisehn avatar evettetelyas avatar raina4trr avatar

Watchers

 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.