You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
943 B

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. package sub_client
  2. import (
  3. "fmt"
  4. "github.com/seaweedfs/seaweedfs/weed/util"
  5. "io"
  6. )
  7. // Subscribe subscribes to a topic's specified partitions.
  8. // If a partition is moved to another broker, the subscriber will automatically reconnect to the new broker.
  9. func (sub *TopicSubscriber) Subscribe() error {
  10. util.RetryUntil("subscribe", func() error {
  11. // ask balancer for brokers of the topic
  12. if err := sub.doLookup(sub.bootstrapBroker); err != nil {
  13. return fmt.Errorf("lookup topic %s/%s: %v", sub.ContentConfig.Namespace, sub.ContentConfig.Topic, err)
  14. }
  15. // treat the first broker as the topic leader
  16. // connect to the leader broker
  17. // subscribe to the topic
  18. if err := sub.doProcess(); err != nil {
  19. return fmt.Errorf("subscribe topic %s/%s: %v", sub.ContentConfig.Namespace, sub.ContentConfig.Topic, err)
  20. }
  21. return nil
  22. }, func(err error) bool {
  23. if err == io.EOF {
  24. return false
  25. }
  26. return true
  27. })
  28. return nil
  29. }