Commit 9ba61f3f authored by AlexStocks's avatar AlexStocks

Fix: add host:port as part of nodeID to defeat a service listens on more than one ports

parent 2c8048f9
......@@ -116,7 +116,9 @@ func NewClient(conf *rpc.ClientConfig, regConf *RegistryConfig, opts ...ClientOp
return clt, nil
}
func (c *Client) Call(ctx context.Context, typ rpc.CodecType, service, method string, args interface{}, reply interface{}) error {
func (c *Client) Call(ctx context.Context, typ rpc.CodecType,
service, method string, args interface{}, reply interface{}) error {
attr := c.attr
attr.Service = service
attr.Protocol = typ.String()
......@@ -130,8 +132,8 @@ func (c *Client) Call(ctx context.Context, typ rpc.CodecType, service, method st
flag = true
}
}
var err error
if flag {
var err error
if svcArray, err = c.filter.Filter(attr); err != nil {
return jerrors.Trace(err)
}
......@@ -144,9 +146,13 @@ func (c *Client) Call(ctx context.Context, typ rpc.CodecType, service, method st
return jerrors.Trace(err)
}
return jerrors.Trace(c.Client.Call(typ,
gxnet.HostAddress(svc.Nodes[0].Address, int(svc.Nodes[0].Port)),
service, method, args, reply))
if len(svc.Nodes) != 1 {
return jerrors.Errorf("illegal service %#v", svc)
}
addr := gxnet.HostAddress(svc.Nodes[0].Address, int(svc.Nodes[0].Port))
return jerrors.Trace(c.Client.Call(typ, addr, service, method, args, reply))
}
func (c *Client) Close() {
......
package micro
import (
"github.com/AlexStocks/goext/net"
"strconv"
"strings"
"time"
......@@ -70,7 +71,8 @@ func NewServer(conf *rpc.ServerConfig, regConf *RegistryConfig) (*Server, error)
nodes = append(nodes,
&gxregistry.Node{
ID: regConf.NodeID,
// use host port as part of NodeID to defeat the case: on process listens on many ports
ID: regConf.NodeID + "@" + gxnet.HostAddress(conf.Host, port),
Address: conf.Host,
Port: int32(port),
},
......@@ -105,8 +107,6 @@ func (s *Server) Register(rcvr rpc.GettyRPCService) error {
return jerrors.Trace(err)
}
s.Stop()
return nil
}
......
......@@ -10,9 +10,9 @@
package getty
const (
Version = "0.9.3"
DATE = "2018/08/07"
GETTY_MAJOR = 0
GETTY_MINOR = 9
GETTY_BUILD = 2
Version = "1.0.1"
DATE = "2018/08/13"
GETTY_MAJOR = 1
GETTY_MINOR = 0
GETTY_BUILD = 1
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment