Пример #1
0
func keepAlive(name string, id string) {
	var err error
	discoveryConf := cfg.GetAgentDiscovery()
	ticker := time.NewTicker(time.Duration(discoveryConf.TTL-1) * time.Second)
	opt := discovery.Options{
		"TTL": time.Duration(discoveryConf.TTL) * time.Second,
	}

	ch_stop := ch.CreateInstanceChannel(id)

	isntanceKey := discoveryConf.AppRoot + "/" + name + "/" + id
	instanceValue := addressMap[id]

	for {
		select {
		case <-ticker.C:
			err = discovery.Set(isntanceKey, instanceValue, opt)
			if err != nil {
				log.WithFields(log.Fields{
					"service":  name,
					"instance": id,
					"address":  instanceValue,
					"err":      err,
				}).Errorln("Error keeping instance alive")
			}
		case <-ch_stop:
			log.Debugln("Stopping keep alive routine")
			return
		}
	}
}
Пример #2
0
func UnregisterServiceInstance(name string, id string) {
	discoveryConf := cfg.GetAgentDiscovery()
	isntanceKey := discoveryConf.AppRoot + "/" + name + "/" + id
	discovery.Delete(isntanceKey)
	ch_stop, err := ch.GetInstanceChannel(id)
	if err != nil {
		log.WithFields(log.Fields{
			"service":  name,
			"instance": id,
			"err":      err,
		}).Errorln("Error getting instance stop channel")
		return
	}
	ch_stop <- struct{}{}
	ch.RemoveInstanceChannel(id)
}
Пример #3
0
func RegisterServiceInstanceId(name string, id string) {
	var err error
	discoveryConf := cfg.GetAgentDiscovery()
	opt := discovery.Options{
		"TTL": time.Duration(discoveryConf.TTL) * time.Second,
	}

	isntanceKey := discoveryConf.AppRoot + "/" + name + "/" + id
	instanceValue := addressMap[id]

	err = discovery.Set(isntanceKey, instanceValue, opt)
	if err != nil {
		log.WithFields(log.Fields{
			"service":  name,
			"instance": id,
			"address":  instanceValue,
			"err":      err,
		}).Errorln("Error registering service instance to discovery service")
	}
}