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.

58 lines
1.4 KiB

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) 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) {
  20. if config == nil {
  21. return
  22. }
  23. validateOneEnabledQueue(config)
  24. for _, queue := range MessageQueues {
  25. if config.GetBool(queue.GetName() + ".enabled") {
  26. viperSub := config.Sub(queue.GetName())
  27. if err := queue.Initialize(viperSub); err != nil {
  28. glog.Fatalf("Failed to initialize notification for %s: %+v",
  29. queue.GetName(), err)
  30. }
  31. Queue = queue
  32. glog.V(0).Infof("Configure notification message queue for %s", queue.GetName())
  33. return
  34. }
  35. }
  36. }
  37. func validateOneEnabledQueue(config *viper.Viper) {
  38. enabledQueue := ""
  39. for _, queue := range MessageQueues {
  40. if config.GetBool(queue.GetName() + ".enabled") {
  41. if enabledQueue == "" {
  42. enabledQueue = queue.GetName()
  43. } else {
  44. glog.Fatalf("Notification message queue is enabled for both %s and %s", enabledQueue, queue.GetName())
  45. }
  46. }
  47. }
  48. }