support direct scheme on rpc resolver

This commit is contained in:
kevin
2020-08-18 18:36:44 +08:00
parent 0214161bfc
commit f03cfb0ff7
11 changed files with 170 additions and 134 deletions

View File

@@ -2,7 +2,9 @@ package main
import (
"context"
"flag"
"fmt"
"log"
"time"
"github.com/tal-tech/go-zero/core/discov"
@@ -10,13 +12,31 @@ import (
"github.com/tal-tech/go-zero/rpcx"
)
var lb = flag.String("t", "direct", "the load balancer type")
func main() {
cli := rpcx.MustNewClient(rpcx.RpcClientConf{
Etcd: discov.EtcdConf{
Hosts: []string{"localhost:2379"},
Key: "rpcx",
},
})
flag.Parse()
var cli rpcx.Client
switch *lb {
case "direct":
cli = rpcx.MustNewClient(rpcx.RpcClientConf{
Endpoints: []string{
"localhost:3456",
"localhost:3457",
},
})
case "discov":
cli = rpcx.MustNewClient(rpcx.RpcClientConf{
Etcd: discov.EtcdConf{
Hosts: []string{"localhost:2379"},
Key: "rpcx",
},
})
default:
log.Fatal("bad load balancing type")
}
greet := unary.NewGreeterClient(cli.Conn())
ticker := time.NewTicker(time.Second)
defer ticker.Stop()