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 ...@@ -116,7 +116,9 @@ func NewClient(conf *rpc.ClientConfig, regConf *RegistryConfig, opts ...ClientOp
return clt, nil 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 := c.attr
attr.Service = service attr.Service = service
attr.Protocol = typ.String() attr.Protocol = typ.String()
...@@ -130,8 +132,8 @@ func (c *Client) Call(ctx context.Context, typ rpc.CodecType, service, method st ...@@ -130,8 +132,8 @@ func (c *Client) Call(ctx context.Context, typ rpc.CodecType, service, method st
flag = true flag = true
} }
} }
var err error
if flag { if flag {
var err error
if svcArray, err = c.filter.Filter(attr); err != nil { if svcArray, err = c.filter.Filter(attr); err != nil {
return jerrors.Trace(err) return jerrors.Trace(err)
} }
...@@ -144,9 +146,13 @@ func (c *Client) Call(ctx context.Context, typ rpc.CodecType, service, method st ...@@ -144,9 +146,13 @@ func (c *Client) Call(ctx context.Context, typ rpc.CodecType, service, method st
return jerrors.Trace(err) return jerrors.Trace(err)
} }
return jerrors.Trace(c.Client.Call(typ, if len(svc.Nodes) != 1 {
gxnet.HostAddress(svc.Nodes[0].Address, int(svc.Nodes[0].Port)), return jerrors.Errorf("illegal service %#v", svc)
service, method, args, reply)) }
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() { func (c *Client) Close() {
......
package micro package micro
import ( import (
"github.com/AlexStocks/goext/net"
"strconv" "strconv"
"strings" "strings"
"time" "time"
...@@ -70,7 +71,8 @@ func NewServer(conf *rpc.ServerConfig, regConf *RegistryConfig) (*Server, error) ...@@ -70,7 +71,8 @@ func NewServer(conf *rpc.ServerConfig, regConf *RegistryConfig) (*Server, error)
nodes = append(nodes, nodes = append(nodes,
&gxregistry.Node{ &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, Address: conf.Host,
Port: int32(port), Port: int32(port),
}, },
...@@ -105,8 +107,6 @@ func (s *Server) Register(rcvr rpc.GettyRPCService) error { ...@@ -105,8 +107,6 @@ func (s *Server) Register(rcvr rpc.GettyRPCService) error {
return jerrors.Trace(err) return jerrors.Trace(err)
} }
s.Stop()
return nil return nil
} }
......
...@@ -10,9 +10,9 @@ ...@@ -10,9 +10,9 @@
package getty package getty
const ( const (
Version = "0.9.3" Version = "1.0.1"
DATE = "2018/08/07" DATE = "2018/08/13"
GETTY_MAJOR = 0 GETTY_MAJOR = 1
GETTY_MINOR = 9 GETTY_MINOR = 0
GETTY_BUILD = 2 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