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.

56 lines
1.4 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. package notification
  2. import (
  3. "github.com/chrislusf/seaweedfs/weed/glog"
  4. "github.com/chrislusf/seaweedfs/weed/util"
  5. "github.com/golang/protobuf/proto"
  6. )
  7. type MessageQueue interface {
  8. // GetName gets the name to locate the configuration in filer.toml file
  9. GetName() string
  10. // Initialize initializes the file store
  11. Initialize(configuration util.Configuration, prefix string) error
  12. SendMessage(key string, message proto.Message) error
  13. }
  14. var (
  15. MessageQueues []MessageQueue
  16. Queue MessageQueue
  17. )
  18. func LoadConfiguration(config *util.ViperProxy, prefix string) {
  19. if config == nil {
  20. return
  21. }
  22. validateOneEnabledQueue(config)
  23. for _, queue := range MessageQueues {
  24. if config.GetBool(prefix + queue.GetName() + ".enabled") {
  25. if err := queue.Initialize(config, prefix+queue.GetName()+"."); err != nil {
  26. glog.Fatalf("Failed to initialize notification for %s: %+v",
  27. queue.GetName(), err)
  28. }
  29. Queue = queue
  30. glog.V(0).Infof("Configure notification message queue for %s", queue.GetName())
  31. return
  32. }
  33. }
  34. }
  35. func validateOneEnabledQueue(config *util.ViperProxy) {
  36. enabledQueue := ""
  37. for _, queue := range MessageQueues {
  38. if config.GetBool(queue.GetName() + ".enabled") {
  39. if enabledQueue == "" {
  40. enabledQueue = queue.GetName()
  41. } else {
  42. glog.Fatalf("Notification message queue is enabled for both %s and %s", enabledQueue, queue.GetName())
  43. }
  44. }
  45. }
  46. }