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.

28 lines
789 B

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. if err := sub.doLookup(sub.bootstrapBroker); err != nil {
  12. return fmt.Errorf("lookup topic %s/%s: %v", sub.ContentConfig.Namespace, sub.ContentConfig.Topic, err)
  13. }
  14. if err := sub.doProcess(); err != nil {
  15. return fmt.Errorf("subscribe topic %s/%s: %v", sub.ContentConfig.Namespace, sub.ContentConfig.Topic, err)
  16. }
  17. return nil
  18. }, func(err error) bool {
  19. if err == io.EOF {
  20. return false
  21. }
  22. return true
  23. })
  24. return nil
  25. }