configuration.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package notification
  2. import (
  3. "github.com/seaweedfs/seaweedfs/weed/glog"
  4. "github.com/seaweedfs/seaweedfs/weed/util"
  5. "google.golang.org/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. }