sub.go 411 B

123456789101112131415161718192021222324
  1. package main
  2. import (
  3. "fmt"
  4. "time"
  5. "github.com/tal-tech/go-zero/core/discov"
  6. "github.com/tal-tech/go-zero/core/logx"
  7. )
  8. func main() {
  9. sub, err := discov.NewSubscriber([]string{"etcd.discovery:2379"}, "028F2C35852D", discov.Exclusive())
  10. logx.Must(err)
  11. ticker := time.NewTicker(time.Second * 3)
  12. defer ticker.Stop()
  13. for {
  14. select {
  15. case <-ticker.C:
  16. fmt.Println("values:", sub.Values())
  17. }
  18. }
  19. }