Merge pull request #669 from printfcoder/master
fix registry addr error for mq-rpc
This commit is contained in:
commit
2dd5109eee
@ -13,6 +13,7 @@ import (
|
|||||||
|
|
||||||
consul "github.com/hashicorp/consul/api"
|
consul "github.com/hashicorp/consul/api"
|
||||||
"github.com/micro/go-micro/registry"
|
"github.com/micro/go-micro/registry"
|
||||||
|
mnet "github.com/micro/go-micro/util/net"
|
||||||
hash "github.com/mitchellh/hashstructure"
|
hash "github.com/mitchellh/hashstructure"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -250,6 +251,9 @@ func (c *consulRegistry) Register(s *registry.Service, opts ...registry.Register
|
|||||||
}
|
}
|
||||||
|
|
||||||
host, pt, _ := net.SplitHostPort(node.Address)
|
host, pt, _ := net.SplitHostPort(node.Address)
|
||||||
|
if host == "" {
|
||||||
|
host = node.Address
|
||||||
|
}
|
||||||
port, _ := strconv.Atoi(pt)
|
port, _ := strconv.Atoi(pt)
|
||||||
|
|
||||||
// register the service
|
// register the service
|
||||||
@ -351,7 +355,7 @@ func (c *consulRegistry) GetService(name string) ([]*registry.Service, error) {
|
|||||||
|
|
||||||
svc.Nodes = append(svc.Nodes, ®istry.Node{
|
svc.Nodes = append(svc.Nodes, ®istry.Node{
|
||||||
Id: id,
|
Id: id,
|
||||||
Address: fmt.Sprintf("%s:%d", address, s.Service.Port),
|
Address: mnet.HostPort(address, s.Service.Port),
|
||||||
Metadata: decodeMetadata(s.Service.Tags),
|
Metadata: decodeMetadata(s.Service.Tags),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -316,10 +316,15 @@ func (s *rpcServer) Register() error {
|
|||||||
md[k] = v
|
md[k] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// mq-rpc(eg. nats) doesn't need the port. its addr is queue name.
|
||||||
|
if port != "" {
|
||||||
|
addr = mnet.HostPort(addr, port)
|
||||||
|
}
|
||||||
|
|
||||||
// register service
|
// register service
|
||||||
node := ®istry.Node{
|
node := ®istry.Node{
|
||||||
Id: config.Name + "-" + config.Id,
|
Id: config.Name + "-" + config.Id,
|
||||||
Address: mnet.HostPort(addr, port),
|
Address: addr,
|
||||||
Metadata: md,
|
Metadata: md,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,12 +14,13 @@ func HostPort(addr string, port interface{}) string {
|
|||||||
if strings.Count(addr, ":") > 0 {
|
if strings.Count(addr, ":") > 0 {
|
||||||
host = fmt.Sprintf("[%s]", addr)
|
host = fmt.Sprintf("[%s]", addr)
|
||||||
}
|
}
|
||||||
// TODO check for NATS case
|
// when port is blank or 0, host is a queue name
|
||||||
if v, ok := port.(string); ok {
|
if v, ok := port.(string); ok && v == "" {
|
||||||
if v == "" {
|
return host
|
||||||
return fmt.Sprintf("%s", host)
|
} else if v, ok := port.(int); ok && v == 0 && net.ParseIP(host) == nil {
|
||||||
}
|
return host
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("%s:%v", host, port)
|
return fmt.Sprintf("%s:%v", host, port)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user