Code Monkey home page Code Monkey logo

grpc-consul-resolver's Introduction

GRPC consul resolver

Feature rich and easy-to-use resolver which return endpoints for service from the Hashicorp Consul and watch for the changes.

This library is production ready and will always save backward-compatibility

Quick Start

For using resolving endpoints from your Hashicorp Consul just import this library with import _ /github.com/mbobakov/grpc-consul-resolver and pass valid connection string to the grpc.Dial.

For full example see this section

Connection string

consul://[user:password@]127.0.0.127:8555/my-service?[healthy=]&[wait=]&[near=]&[insecure=]&[limit=]&[tag=]&[token=]

Parameters:

Name Format Description
tag string Select endpoints only with this tag
healthy true/false Return only endpoints which pass all health-checks. Default: false
wait as in time.ParseDuration Wait time for watch changes. Due this time period endpoints will be force refreshed. Default: inherits agent property
insecure true/false Allow insecure communication with Consul. Default: true
near string Sort endpoints by response duration. Can be efficient combine with limit parameter default: "_agent"
limit int Limit number of endpoints for the service. Default: no limit
timeout as in time.ParseDuration Http-client timeout. Default: 60s
token string Consul token

Example

package main

import (
	"time"
	"log"
	
	_ "github.com/mbobakov/grpc-consul-resolver" // It's important
	
	"google.golang.org/grpc"
)

func main() {
    conn, err := grpc.Dial(
        "consul://127.0.0.1:8500/whoami?wait=14s&tag=manual",
        grpc.WithInsecure(), 
        grpc.WithBalancerName("round_robin"),
    )
    if err != nil {
        log.Fatal(err)
    }
    defer conn.Close()
    ...
}

License

MIT-LICENSE. See LICENSE or the LICENSE file provided in the repository for details.

grpc-consul-resolver's People

Contributors

fbsdeploy avatar mbobakov avatar

Watchers

 avatar  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.