コード例 #1
0
ファイル: bamboo.go プロジェクト: Dataman-Cloud/bamboo
func listenToZookeeper(conf configuration.Configuration, eventBus *event_bus.EventBus) *zk.Conn {
	serviceConf := conf.Bamboo.Zookeeper
	serviceConf.Path = fmt.Sprintf("%s/%s", serviceConf.Path, "services")
	serviceCh, serviceConn := createAndListen(serviceConf)

	weightConf := conf.Bamboo.Zookeeper
	weightConf.Path = fmt.Sprintf("%s/%s", weightConf.Path, "weights")
	weightCh, _ := createAndListen(weightConf)

	go func() {
		for {
			select {
			case <-serviceCh:
				eventBus.Publish(event_bus.ServiceEvent{EventType: "change"})
			}
		}
	}()
	go func() {
		for {
			select {
			case <-weightCh:
				eventBus.Publish(event_bus.WeightEvent{EventType: "change"})
			}
		}
	}()

	return serviceConn
}
コード例 #2
0
func listenToZookeeper(conf configuration.Configuration, eventBus *event_bus.EventBus) *zk.Conn {
	serviceCh, serviceConn := createAndListen(conf.Bamboo.Zookeeper)

	go func() {
		for {
			select {
			case _ = <-serviceCh:
				eventBus.Publish(event_bus.ServiceEvent{EventType: "change"})
			}
		}
	}()
	return serviceConn
}