Пример #1
0
func init() {
	Expect = make(map[string]chan []byte)

	// spawn worker to monitor key space change; KEY UPDATE
	go func() {
		regevent := redis.KeySpaceEventLoop()

		client := redis.NewClient()
		defer client.Close()

		for event := range regevent {
			target, ok := Expect[event.Key]
			if !ok {
				continue
			}
			switch event.Action {
			case "expired":
				close(target)
				break
			case "append":
				val, err := client.Get(event.Key).Result()
				if err != nil {
					panic(err)
				}
				target <- []byte(val)
				break
			}
		}
	}()

	Server.HandleFunc("/provision", Provision)
	Server.HandleFunc("/deprovision", Deprovision)
}
Пример #2
0
func init() {
	go func() {
		queue := make(map[string]chan registry.Serializer)

		// spawn worker to monitor redis keyspace
		regevent := redis.KeySpaceEventLoop()

		for action := range regevent {
			if dest, ok := queue[action.Tier]; !ok {
				queue[action.Tier] = make(chan registry.Serializer, 4)
				queue[action.Tier] <- action
				rabbitmq.NamedSendLoop(action.Tier, queue[action.Tier])
			} else {
				dest <- action
			}
		}
	}()
}