go-zero/example/etcd/sub/sub.go

25 lines
411 B
Go
Raw Normal View History

2020-07-26 17:09:05 +08:00
package main
import (
"fmt"
"time"
2020-08-08 16:40:10 +08:00
"github.com/tal-tech/go-zero/core/discov"
"github.com/tal-tech/go-zero/core/logx"
2020-07-26 17:09:05 +08:00
)
func main() {
2020-07-30 22:56:39 +08:00
sub, err := discov.NewSubscriber([]string{"etcd.discovery:2379"}, "028F2C35852D", discov.Exclusive())
logx.Must(err)
2020-07-30 22:56:39 +08:00
2020-07-26 17:09:05 +08:00
ticker := time.NewTicker(time.Second * 3)
defer ticker.Stop()
for {
select {
case <-ticker.C:
fmt.Println("values:", sub.Values())
}
}
}