Skip to content

Commit

Permalink
update bug
Browse files Browse the repository at this point in the history
  • Loading branch information
iGoogle-ink committed Oct 19, 2020
1 parent 63acf9e commit dface21
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
18 changes: 15 additions & 3 deletions rpcx/clientv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type (
DialOptions []grpc.DialOption //RPC链接可选参数
}
GrpcClientConfig struct {
name string
Name []string
Timeout string //超时时间,默认:5s
MaxAttempts string //最大重试次数,必须是大于 1 的整数,对于大于5的值会被视为5,默认:4
InitialBackoff string //第一次重试默认时间间隔,必须具有大于0,默认:2s
Expand All @@ -42,7 +42,7 @@ type (

func defaultClientConfig(name string) *GrpcClientConfig {
return &GrpcClientConfig{
name: name,
Name: []string{name},
Timeout: "5s",
MaxAttempts: "2",
InitialBackoff: "2s",
Expand Down Expand Up @@ -150,6 +150,18 @@ func (clientConfig *ClientConfig) buildDialOptions() []grpc.DialOption {

// withDefaultServiceConfig
func (c *GrpcClientConfig) withDefaultServiceConfig() grpc.DialOption {
nameArr := make([]map[string]string, 0)
for k1 := range c.Name {
name := map[string]string{
"service": c.Name[k1],
}
nameArr = append(nameArr, name)
}
nameByte, err := json.Marshal(nameArr)
if err != nil {
log.Print(string(nameByte))
}

retryableStatusCodesArr := make([]string, 0)
for k1 := range c.RetryableStatusCodes {
retryableStatusCodesArr = append(retryableStatusCodesArr, c.RetryableStatusCodes[k1])
Expand Down Expand Up @@ -184,7 +196,7 @@ func (c *GrpcClientConfig) withDefaultServiceConfig() grpc.DialOption {
"maxTokens":%s,
"tokenRatio":%s
}
}`, roundrobin.Name, c.name, c.WaitForReady, c.Timeout, c.MaxAttempts, c.InitialBackoff, c.MaxBackoff, c.BackoffMultiplier, string(retryableStatusCodesByte), c.MaxTokens, c.TokenRatio)
}`, roundrobin.Name, string(nameByte), c.WaitForReady, c.Timeout, c.MaxAttempts, c.InitialBackoff, c.MaxBackoff, c.BackoffMultiplier, string(retryableStatusCodesByte), c.MaxTokens, c.TokenRatio)
return grpc.WithDefaultServiceConfig(retryPolicy)
}

Expand Down
17 changes: 17 additions & 0 deletions rpcx/grpc_client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package rpcx

import (
"testing"
)

func TestNewGrpcClient(t *testing.T) {
//client, err := NewGrpcClient("grpc", "127.0.0.1:11007", nil)
//if err != nil {
// xlog.Error(err)
// return
//}
//conn, ok := client.Conn()
//if ok {
// conn = conn
//}
}

0 comments on commit dface21

Please sign in to comment.