switch to direct resolver

pull/109/head
longXboy 6 years ago
parent 457908d64b
commit 24a710968b
  1. 1
      pkg/net/rpc/warden/CHANGELOG.md
  2. 8
      pkg/net/rpc/warden/client.go
  3. 2
      pkg/net/rpc/warden/internal/examples/client/client.go

@ -1,4 +1,5 @@
### net/rpc/warden
##### Version 1.1.12
1. 设置 caller 为 no_user 如果 user 不存在

@ -14,12 +14,12 @@ import (
"github.com/bilibili/kratos/pkg/conf/flagvar"
"github.com/bilibili/kratos/pkg/ecode"
"github.com/bilibili/kratos/pkg/naming"
"github.com/bilibili/kratos/pkg/naming/discovery"
nmd "github.com/bilibili/kratos/pkg/net/metadata"
"github.com/bilibili/kratos/pkg/net/netutil/breaker"
"github.com/bilibili/kratos/pkg/net/rpc/warden/balancer/p2c"
"github.com/bilibili/kratos/pkg/net/rpc/warden/internal/status"
"github.com/bilibili/kratos/pkg/net/rpc/warden/resolver"
"github.com/bilibili/kratos/pkg/net/rpc/warden/resolver/direct"
"github.com/bilibili/kratos/pkg/net/trace"
xtime "github.com/bilibili/kratos/pkg/time"
@ -156,7 +156,7 @@ func NewConn(target string, opt ...grpc.DialOption) (*grpc.ClientConn, error) {
// NewClient returns a new blank Client instance with a default client interceptor.
// opt can be used to add grpc dial options.
func NewClient(conf *ClientConfig, opt ...grpc.DialOption) *Client {
resolver.Register(discovery.Builder())
resolver.Register(direct.New())
c := new(Client)
if err := c.SetConfig(conf); err != nil {
panic(err)
@ -170,7 +170,7 @@ func NewClient(conf *ClientConfig, opt ...grpc.DialOption) *Client {
// DefaultClient returns a new default Client instance with a default client interceptor and default dialoption.
// opt can be used to add grpc dial options.
func DefaultClient() *Client {
resolver.Register(discovery.Builder())
resolver.Register(direct.New())
_once.Do(func() {
_defaultClient = NewClient(nil)
})
@ -226,7 +226,7 @@ func (c *Client) UseOpt(opt ...grpc.DialOption) *Client {
// Dial creates a client connection to the given target.
// Target format is scheme://authority/endpoint?query_arg=value
// example: discovery://default/account.account.service?cluster=shfy01&cluster=shfy02
// example: direct://default/192.168.1.1:8080,192.168.1.2:8081
func (c *Client) Dial(ctx context.Context, target string, opt ...grpc.DialOption) (conn *grpc.ClientConn, err error) {
if !c.conf.NonBlock {
c.opt = append(c.opt, grpc.WithBlock())

@ -14,7 +14,7 @@ import (
func main() {
log.Init(&log.Config{Stdout: true})
flag.Parse()
conn, err := warden.NewClient(nil).Dial(context.Background(), "127.0.0.1:8081")
conn, err := warden.NewClient(nil).Dial(context.Background(), "direct://d/127.0.0.1:8081")
if err != nil {
panic(err)
}

Loading…
Cancel
Save