百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
G

grpc-consul-resolver

> 编程语言
开源

易于插入的全功能 GRPC 解析器,用于在 Consul 中注册的服务

353 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

易于插入的全功能 GRPC 解析器,用于在 Consul 中注册的服务

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
max-backoff as in time.ParseDuration Max backoff time for reconnect to consul. Reconnects will start from 10ms to max-backoff exponentialy with factor 2. Default: 1s
token string Consul token
dc string Consul datacenter to choose. Optional
allow-stale true/false Allow stale results from the agent. https://www.consul.io/api/features/consistency.html#stale
require-consistent true/false RequireConsistent forces the read to be fully consistent. This is more expensive but prevents ever performing a stale read.

Example

go
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.WithDefaultServiceConfig(`{"loadBalancingPolicy": "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.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Goconsulgrpcgrpc-consul-resolverresolver

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言