Merge pull request #109 from bilibili/warden/direct_dial

switch to direct resolver
pull/121/head
longxboy 6 years ago committed by GitHub
commit 7df17c33ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      pkg/net/rpc/warden/CHANGELOG.md
  2. 6
      pkg/net/rpc/warden/client.go
  3. 2
      pkg/net/rpc/warden/internal/examples/client/client.go
  4. 3
      pkg/net/rpc/warden/resolver/direct/test/direct_test.go
  5. 3
      pkg/net/rpc/warden/server.go

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

@ -14,12 +14,10 @@ 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/trace"
xtime "github.com/bilibili/kratos/pkg/time"
@ -156,7 +154,6 @@ 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())
c := new(Client)
if err := c.SetConfig(conf); err != nil {
panic(err)
@ -170,7 +167,6 @@ 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())
_once.Do(func() {
_defaultClient = NewClient(nil)
})
@ -226,7 +222,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)
}

@ -11,6 +11,7 @@ import (
"github.com/bilibili/kratos/pkg/net/rpc/warden"
pb "github.com/bilibili/kratos/pkg/net/rpc/warden/internal/proto/testproto"
"github.com/bilibili/kratos/pkg/net/rpc/warden/resolver"
"github.com/bilibili/kratos/pkg/net/rpc/warden/resolver/direct"
xtime "github.com/bilibili/kratos/pkg/time"
)
@ -39,7 +40,7 @@ func createServer(name, listen string) *warden.Server {
}
func TestMain(m *testing.M) {
resolver.Register(New())
resolver.Register(direct.New())
ctx := context.TODO()
s1 := createServer("server1", "127.0.0.1:18081")
s2 := createServer("server2", "127.0.0.1:18082")

@ -19,6 +19,8 @@ import (
//this package is for json format response
_ "github.com/bilibili/kratos/pkg/net/rpc/warden/internal/encoding/json"
"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/pkg/errors"
"google.golang.org/grpc"
@ -135,6 +137,7 @@ func (s *Server) handle() grpc.UnaryServerInterceptor {
func init() {
addFlag(flag.CommandLine)
resolver.Register(direct.New())
}
func addFlag(fs *flag.FlagSet) {

Loading…
Cancel
Save