Moving to gRPC by default (#1069)

* Step 1

* Fix the test panics
This commit is contained in:
Asim Aslam 2019-12-29 21:07:55 +00:00 committed by Vasiliy Tolstov
parent 01ad981688
commit 7d5e31cd58
3 changed files with 30 additions and 58 deletions

36
grpc.go
View File

@ -12,12 +12,10 @@ import (
"github.com/micro/go-micro/broker" "github.com/micro/go-micro/broker"
"github.com/micro/go-micro/client" "github.com/micro/go-micro/client"
"github.com/micro/go-micro/client/selector" "github.com/micro/go-micro/client/selector"
"github.com/micro/go-micro/codec"
raw "github.com/micro/go-micro/codec/bytes" raw "github.com/micro/go-micro/codec/bytes"
"github.com/micro/go-micro/errors" "github.com/micro/go-micro/errors"
"github.com/micro/go-micro/metadata" "github.com/micro/go-micro/metadata"
"github.com/micro/go-micro/registry" "github.com/micro/go-micro/registry"
"github.com/micro/go-micro/transport"
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/credentials" "google.golang.org/grpc/credentials"
@ -623,45 +621,19 @@ func (g *grpcClient) getGrpcCallOptions() []grpc.CallOption {
} }
func newClient(opts ...client.Option) client.Client { func newClient(opts ...client.Option) client.Client {
options := client.Options{ options := client.NewOptions()
Codecs: make(map[string]codec.NewCodec), // default content type for grpc
CallOptions: client.CallOptions{ options.ContentType = "application/grpc+proto"
Backoff: client.DefaultBackoff,
Retry: client.DefaultRetry,
Retries: client.DefaultRetries,
RequestTimeout: client.DefaultRequestTimeout,
DialTimeout: transport.DefaultDialTimeout,
},
PoolSize: client.DefaultPoolSize,
PoolTTL: client.DefaultPoolTTL,
}
for _, o := range opts { for _, o := range opts {
o(&options) o(&options)
} }
if len(options.ContentType) == 0 {
options.ContentType = "application/grpc+proto"
}
if options.Broker == nil {
options.Broker = broker.DefaultBroker
}
if options.Registry == nil {
options.Registry = registry.DefaultRegistry
}
if options.Selector == nil {
options.Selector = selector.NewSelector(
selector.Registry(options.Registry),
)
}
rc := &grpcClient{ rc := &grpcClient{
once: sync.Once{}, once: sync.Once{},
opts: options, opts: options,
} }
rc.pool = newPool(options.PoolSize, options.PoolTTL, rc.poolMaxIdle(), rc.poolMaxStreams()) rc.pool = newPool(options.PoolSize, options.PoolTTL, rc.poolMaxIdle(), rc.poolMaxStreams())
c := client.Client(rc) c := client.Client(rc)