mirror of
https://github.com/go-micro/go-micro.git
synced 2024-11-30 08:06:40 +02:00
Merge pull request #202 from freman/mapsorting
Fix hashing of the service definition
This commit is contained in:
commit
8be72b676d
@ -3,6 +3,7 @@ package server
|
||||
import (
|
||||
"fmt"
|
||||
"runtime/debug"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@ -232,19 +233,34 @@ func (s *rpcServer) Register() error {
|
||||
node.Metadata["registry"] = config.Registry.String()
|
||||
|
||||
s.RLock()
|
||||
var endpoints []*registry.Endpoint
|
||||
for _, e := range s.handlers {
|
||||
// Maps are ordered randomly, sort the keys for consistency
|
||||
var handlerList []string
|
||||
for n, e := range s.handlers {
|
||||
// Only advertise non internal handlers
|
||||
if !e.Options().Internal {
|
||||
endpoints = append(endpoints, e.Endpoints()...)
|
||||
handlerList = append(handlerList, n)
|
||||
}
|
||||
}
|
||||
for e, _ := range s.subscribers {
|
||||
sort.Strings(handlerList)
|
||||
|
||||
var subscriberList []*subscriber
|
||||
for e := range s.subscribers {
|
||||
// Only advertise non internal subscribers
|
||||
if !e.Options().Internal {
|
||||
endpoints = append(endpoints, e.Endpoints()...)
|
||||
subscriberList = append(subscriberList, e)
|
||||
}
|
||||
}
|
||||
sort.Slice(subscriberList, func(i, j int) bool {
|
||||
return subscriberList[i].topic > subscriberList[j].topic
|
||||
})
|
||||
|
||||
var endpoints []*registry.Endpoint
|
||||
for _, n := range handlerList {
|
||||
endpoints = append(endpoints, s.handlers[n].Endpoints()...)
|
||||
}
|
||||
for _, e := range subscriberList {
|
||||
endpoints = append(endpoints, e.Endpoints()...)
|
||||
}
|
||||
s.RUnlock()
|
||||
|
||||
service := ®istry.Service{
|
||||
|
Loading…
Reference in New Issue
Block a user