Deprecate client/selector (#1767)

* client/{grpc,rpc}: depricate selector (wip)

* {client,cmd}: remove client/selector

* deprecate client/selector

* router/static: fix lookup

* config/cmd: add support for legacy static selector flag

* config/cmd: add support for legacy dns selector flag
This commit is contained in:
ben-toogood 2020-07-01 17:06:59 +01:00 committed by Vasiliy Tolstov
parent 4d24368bf5
commit b8d2c5dd23
2 changed files with 10 additions and 17 deletions

19
rpc.go
View File

@ -12,16 +12,15 @@ import (
jsonpatch "github.com/evanphx/json-patch/v5" jsonpatch "github.com/evanphx/json-patch/v5"
"github.com/micro/go-micro/v2/api" "github.com/micro/go-micro/v2/api"
"github.com/micro/go-micro/v2/api/handler" "github.com/micro/go-micro/v2/api/handler"
"github.com/micro/go-micro/v2/api/handler/util"
"github.com/micro/go-micro/v2/api/internal/proto" "github.com/micro/go-micro/v2/api/internal/proto"
"github.com/micro/go-micro/v2/client" "github.com/micro/go-micro/v2/client"
"github.com/micro/go-micro/v2/client/selector"
"github.com/micro/go-micro/v2/codec" "github.com/micro/go-micro/v2/codec"
"github.com/micro/go-micro/v2/codec/jsonrpc" "github.com/micro/go-micro/v2/codec/jsonrpc"
"github.com/micro/go-micro/v2/codec/protorpc" "github.com/micro/go-micro/v2/codec/protorpc"
"github.com/micro/go-micro/v2/errors" "github.com/micro/go-micro/v2/errors"
"github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/logger"
"github.com/micro/go-micro/v2/metadata" "github.com/micro/go-micro/v2/metadata"
"github.com/micro/go-micro/v2/registry"
"github.com/micro/go-micro/v2/util/ctx" "github.com/micro/go-micro/v2/util/ctx"
"github.com/micro/go-micro/v2/util/qson" "github.com/micro/go-micro/v2/util/qson"
"github.com/oxtoacart/bpool" "github.com/oxtoacart/bpool"
@ -65,14 +64,6 @@ func (b *buffer) Write(_ []byte) (int, error) {
return 0, nil return 0, nil
} }
// strategy is a hack for selection
func strategy(services []*registry.Service) selector.Strategy {
return func(_ []*registry.Service) selector.Next {
// ignore input to this function, use services above
return selector.Random(services)
}
}
func (h *rpcHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (h *rpcHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
bsize := handler.DefaultMaxRecvSize bsize := handler.DefaultMaxRecvSize
if h.opts.MaxRecvSize > 0 { if h.opts.MaxRecvSize > 0 {
@ -141,8 +132,8 @@ func (h *rpcHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return return
} }
// create strategy // create custom router
so := selector.WithStrategy(strategy(service.Services)) callOpt := client.WithRouter(util.Router(service.Services))
// walk the standard call path // walk the standard call path
// get payload // get payload
@ -174,7 +165,7 @@ func (h *rpcHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
) )
// make the call // make the call
if err := c.Call(cx, req, response, client.WithSelectOption(so)); err != nil { if err := c.Call(cx, req, response, callOpt); err != nil {
writeError(w, r, err) writeError(w, r, err)
return return
} }
@ -209,7 +200,7 @@ func (h *rpcHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
client.WithContentType(ct), client.WithContentType(ct),
) )
// make the call // make the call
if err := c.Call(cx, req, &response, client.WithSelectOption(so)); err != nil { if err := c.Call(cx, req, &response, callOpt); err != nil {
writeError(w, r, err) writeError(w, r, err)
return return
} }

View File

@ -13,8 +13,8 @@ import (
"github.com/gobwas/ws" "github.com/gobwas/ws"
"github.com/gobwas/ws/wsutil" "github.com/gobwas/ws/wsutil"
"github.com/micro/go-micro/v2/api" "github.com/micro/go-micro/v2/api"
"github.com/micro/go-micro/v2/api/handler/util"
"github.com/micro/go-micro/v2/client" "github.com/micro/go-micro/v2/client"
"github.com/micro/go-micro/v2/client/selector"
raw "github.com/micro/go-micro/v2/codec/bytes" raw "github.com/micro/go-micro/v2/codec/bytes"
"github.com/micro/go-micro/v2/logger" "github.com/micro/go-micro/v2/logger"
) )
@ -110,9 +110,11 @@ func serveWebsocket(ctx context.Context, w http.ResponseWriter, r *http.Request,
client.StreamingRequest(), client.StreamingRequest(),
) )
so := selector.WithStrategy(strategy(service.Services)) // create custom router
callOpt := client.WithRouter(util.Router(service.Services))
// create a new stream // create a new stream
stream, err := c.Stream(ctx, req, client.WithSelectOption(so)) stream, err := c.Stream(ctx, req, callOpt)
if err != nil { if err != nil {
if logger.V(logger.ErrorLevel, logger.DefaultLogger) { if logger.V(logger.ErrorLevel, logger.DefaultLogger) {
logger.Error(err) logger.Error(err)