mirror of
https://github.com/go-kratos/kratos.git
synced 2025-02-13 13:48:51 +02:00
add rpc withBlock dialOption
This commit is contained in:
parent
b8999dd99d
commit
22e7564832
@ -219,6 +219,7 @@ const AppID = "demo.service" // NOTE: example
|
||||
func init(){
|
||||
// NOTE: 注意这段代码,表示要使用etcd进行服务发现 ,其他事项参考discovery的说明
|
||||
// NOTE: 在启动应用时,可以通过flag(-etcd.endpoints) 或者 环境配置(ETCD_ENDPOINTS)指定etcd节点
|
||||
// NOTE: 如果需要自己指定配置时 需要同时设置DialTimeout 与 DialOptions: []grpc.DialOption{grpc.WithBlock()}
|
||||
resolver.Register(etcd.Builder(nil))
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ import (
|
||||
"github.com/bilibili/kratos/pkg/naming"
|
||||
"go.etcd.io/etcd/clientv3"
|
||||
"go.etcd.io/etcd/mvcc/mvccpb"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -99,6 +100,7 @@ func New(c *clientv3.Config) (e *EtcdBuilder, err error) {
|
||||
c = &clientv3.Config{
|
||||
Endpoints: strings.Split(endpoints, ","),
|
||||
DialTimeout: time.Second * time.Duration(defaultDialTimeout),
|
||||
DialOptions: []grpc.DialOption{grpc.WithBlock()},
|
||||
}
|
||||
}
|
||||
cli, err := clientv3.New(*c)
|
||||
|
@ -3,10 +3,11 @@ package etcd
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/bilibili/kratos/pkg/naming"
|
||||
"go.etcd.io/etcd/clientv3"
|
||||
"testing"
|
||||
"time"
|
||||
"github.com/bilibili/kratos/pkg/naming"
|
||||
"go.etcd.io/etcd/clientv3"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func TestNew(t *testing.T) {
|
||||
@ -14,6 +15,7 @@ func TestNew(t *testing.T) {
|
||||
config := &clientv3.Config{
|
||||
Endpoints: []string{"127.0.0.1:2379"},
|
||||
DialTimeout: time.Second * 3,
|
||||
DialOptions: []grpc.DialOption{grpc.WithBlock()},
|
||||
}
|
||||
builder, err := New(config)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user