// Forget removes a buddy from the buddy list func Forget(dependencies *map[string]time.Time, router *ribbon.Router, msg gotocol.Message) { microservice := msg.Intention // message body is buddy name to forget if router.Named(microservice) != nil { // an existing buddy to forget // forget how to talk to this buddy (*dependencies)[names.Service(microservice)] = msg.Sent // remember when we were told to forget this service router.Remove(microservice) } }
// NameDrop updates local buddy list func NameDrop(dependencies *map[string]time.Time, router *ribbon.Router, msg gotocol.Message, name string, listener chan gotocol.Message, eureka map[string]chan gotocol.Message, crosszone ...bool) { if msg.ResponseChan == nil { // dependency by service name, needs to be looked up in eureka (*dependencies)[msg.Intention] = msg.Sent // remember it for later for _, ch := range eureka { //log.Println(name + " looking up " + msg.Intention) gotocol.Send(ch, gotocol.Message{gotocol.GetRequest, listener, time.Now(), gotocol.NilContext, msg.Intention}) } } else { // update dependency with full name and listener channel microservice := msg.Intention // message body is buddy name if len(crosszone) > 0 || names.Zone(name) == names.Zone(microservice) { if microservice != name && router.Named(microservice) == nil { // don't talk to myself or record duplicates // remember how to talk to this buddy router.Add(microservice, msg.ResponseChan, msg.Sent) // message channel is buddy's listener (*dependencies)[names.Service(microservice)] = msg.Sent for _, ch := range eureka { // tell just one of the service registries I have a new buddy to talk to so it doesn't get logged more than once gotocol.Send(ch, gotocol.Message{gotocol.Inform, listener, time.Now(), gotocol.NilContext, name + " " + microservice}) return } } } } }