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.

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