pusher.go 546 B

12345678910111213141516171819202122232425262728293031
  1. package main
  2. import (
  3. "log"
  4. "strconv"
  5. "time"
  6. "zero/core/discov"
  7. "zero/rq"
  8. "github.com/google/gops/agent"
  9. )
  10. func main() {
  11. if err := agent.Listen(agent.Options{}); err != nil {
  12. log.Fatal(err)
  13. }
  14. pusher, err := rq.NewPusher([]string{"localhost:2379"}, "queue", rq.WithConsistentStrategy(
  15. func(msg string) (string, string, error) {
  16. return msg, msg, nil
  17. }, discov.BalanceWithId()), rq.WithServerSensitive())
  18. if err != nil {
  19. log.Fatal(err)
  20. }
  21. for i := 0; ; i++ {
  22. pusher.Push(strconv.Itoa(i))
  23. time.Sleep(time.Second)
  24. }
  25. }