add rpc withBlock dialOption

pull/229/head
LibiChai 5 years ago
parent b8999dd99d
commit 22e7564832
  1. 1
      doc/wiki-cn/warden-resolver.md
  2. 2
      pkg/naming/etcd/etcd.go
  3. 6
      pkg/naming/etcd/etcd_test.go

@ -219,6 +219,7 @@ const AppID = "demo.service" // NOTE: example
func init(){ func init(){
// NOTE: 注意这段代码,表示要使用etcd进行服务发现 ,其他事项参考discovery的说明 // NOTE: 注意这段代码,表示要使用etcd进行服务发现 ,其他事项参考discovery的说明
// NOTE: 在启动应用时,可以通过flag(-etcd.endpoints) 或者 环境配置(ETCD_ENDPOINTS)指定etcd节点 // NOTE: 在启动应用时,可以通过flag(-etcd.endpoints) 或者 环境配置(ETCD_ENDPOINTS)指定etcd节点
// NOTE: 如果需要自己指定配置时 需要同时设置DialTimeout 与 DialOptions: []grpc.DialOption{grpc.WithBlock()}
resolver.Register(etcd.Builder(nil)) resolver.Register(etcd.Builder(nil))
} }

@ -16,6 +16,7 @@ import (
"github.com/bilibili/kratos/pkg/naming" "github.com/bilibili/kratos/pkg/naming"
"go.etcd.io/etcd/clientv3" "go.etcd.io/etcd/clientv3"
"go.etcd.io/etcd/mvcc/mvccpb" "go.etcd.io/etcd/mvcc/mvccpb"
"google.golang.org/grpc"
) )
var ( var (
@ -99,6 +100,7 @@ func New(c *clientv3.Config) (e *EtcdBuilder, err error) {
c = &clientv3.Config{ c = &clientv3.Config{
Endpoints: strings.Split(endpoints, ","), Endpoints: strings.Split(endpoints, ","),
DialTimeout: time.Second * time.Duration(defaultDialTimeout), DialTimeout: time.Second * time.Duration(defaultDialTimeout),
DialOptions: []grpc.DialOption{grpc.WithBlock()},
} }
} }
cli, err := clientv3.New(*c) cli, err := clientv3.New(*c)

@ -3,10 +3,11 @@ package etcd
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/bilibili/kratos/pkg/naming"
"go.etcd.io/etcd/clientv3"
"testing" "testing"
"time" "time"
"github.com/bilibili/kratos/pkg/naming"
"go.etcd.io/etcd/clientv3"
"google.golang.org/grpc"
) )
func TestNew(t *testing.T) { func TestNew(t *testing.T) {
@ -14,6 +15,7 @@ func TestNew(t *testing.T) {
config := &clientv3.Config{ config := &clientv3.Config{
Endpoints: []string{"127.0.0.1:2379"}, Endpoints: []string{"127.0.0.1:2379"},
DialTimeout: time.Second * 3, DialTimeout: time.Second * 3,
DialOptions: []grpc.DialOption{grpc.WithBlock()},
} }
builder, err := New(config) builder, err := New(config)

Loading…
Cancel
Save